blob: 0fbd8de22cf84e152ba22bb47ca9b89f1c6605fe [file] [log] [blame]
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Tests lookup of type literals of user-defined classes in const maps.
import 'package:expect/expect.dart';
class A {}
class C<T> {}
typedef F = T Function<T>();
typedef Cint = C<int>;
const aType = A;
const fType = F;
const cIntType = Cint;
main() {
final map = const {A: 42, F: 2, 'asdf': 'fdsa', Cint: 'foo'};
Expect.equals(42, map[getValueNonOptimized(A)]);
Expect.equals(42, map[getValueNonOptimized(aType)]);
Expect.equals(2, map[getValueNonOptimized(F)]);
Expect.equals(2, map[getValueNonOptimized(fType)]);
Expect.equals('foo', map[getValueNonOptimized(Cint)]);
Expect.equals('foo', map[getValueNonOptimized(cIntType)]);
/// Returns its argument.
/// Prevents static optimizations and inlining.
dynamic getValueNonOptimized(dynamic x) {
// cannot be predicted statically, never equal to 42.
if ( == 42) {
return getValueNonOptimized(2);
return x;