Files
sdk/tests/language/const/map3_test.dart
T
Konstantin Shcheglov 3f288db57e Issue 51046. Implement primitive equality.
Bug: https://github.com/dart-lang/sdk/issues/51046
Change-Id: I2190b9e36753cc5f4708597ae0b515430d2f7bf2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283440
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-02-18 06:22:04 +00:00

33 lines
881 B
Dart

// Copyright (c) 2014, 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.
import "package:expect/expect.dart";
class A {
static const b = const B();
}
class B implements A {
const B();
operator ==(o) => true;
}
main() {
// It is a compile-time error if the key type overrides operator ==.
dynamic m = const {A.b: 42};
// ^
// [cfe] Constant evaluation error:
// ^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_MAP_KEY_NOT_PRIMITIVE_EQUALITY
Expect.equals(42, m[const B()]);
m = const {"foo": 99, A.b: 499};
// ^
// [cfe] Constant evaluation error:
// ^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_MAP_KEY_NOT_PRIMITIVE_EQUALITY
Expect.equals(499, m[const B()]);
}