[flip-patterns] Update language/constants_2018/equals_test.dart for primitive equality.

We've changed const `==` to be based on primitive equality. It used to
just be an allowed list of concrete types, but now `==` is a valid
constant expression on any type that has primitive equality.

This change isn't directly part of patterns, but is enabled under the
same flag.

Update this test to the new semantics.

Change-Id: I484bd09f5775319dc49038d70a244c3c1564fe93
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286865
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Robert Nystrom 2023-03-03 23:39:37 +00:00 committed by Commit Queue
parent c67fac9cb4
commit e8d44461ce

View file

@ -4,30 +4,37 @@
// Tests that equality is allowed for receivers of specific types.
// SharedOptions=--enable-experiment=patterns,records
import "package:expect/expect.dart";
main() {
const c = C(); // Does not override operator==.
const d = D(); // Overrides operator==.
// Allowed if receiver is int, double, String, bool or Null, ...
// Allowed if receiver has primitive equality...
Expect.isTrue(const T.eq(1, 1).value);
Expect.isTrue(const T.eq(1.5, 1.5).value);
Expect.isTrue(const T.eq("", "").value);
Expect.isTrue(const T.eq(true, true).value);
Expect.isTrue(const T.eq(null, null).value);
Expect.isTrue(const T.eq(c, c).value);
Expect.isTrue(const T.eq(E.value1, E.value1).value);
Expect.isFalse(const T.eq(1, c).value);
Expect.isFalse(const T.eq(1.5, c).value);
Expect.isFalse(const T.eq("", c).value);
Expect.isFalse(const T.eq(true, c).value);
Expect.isFalse(const T.eq(null, c).value);
Expect.isFalse(const T.eq(E.value1, c).value);
Expect.isFalse(const T.eq(1, d).value);
Expect.isFalse(const T.eq(1.5, d).value);
Expect.isFalse(const T.eq("", d).value);
Expect.isFalse(const T.eq(true, d).value);
Expect.isFalse(const T.eq(null, d).value);
Expect.isFalse(const T.eq(c, d).value);
Expect.isFalse(const T.eq(E.value1, d).value);
// ... or if second operand is Null.
Expect.isFalse(const T.eq(1, null).value);
@ -38,10 +45,10 @@ main() {
Expect.isFalse(const T.eq(d, null).value);
// Otherwise not allowed.
const T.eq(c, c); //# 01: compile-time error
const T.eq(c, 1); //# 02: compile-time error
const T.eq(c, ""); //# 03: compile-time error
const T.eq(E.value1, E.value2); //# 04: compile-time error
const T.eq(d, d); //# 01: compile-time error
const T.eq(d, 1); //# 02: compile-time error
const T.eq(d, ""); //# 03: compile-time error
const T.eq(d, c); //# 04: compile-time error
}
class T {