From e8d44461ce826f534eee20d4a163f3e9e7f55fc8 Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Fri, 3 Mar 2023 23:39:37 +0000 Subject: [PATCH] [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 Reviewed-by: Jake Macdonald Auto-Submit: Bob Nystrom --- tests/language/constants_2018/equals_test.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/language/constants_2018/equals_test.dart b/tests/language/constants_2018/equals_test.dart index 9e50b76b62c..bb0bf2833e6 100644 --- a/tests/language/constants_2018/equals_test.dart +++ b/tests/language/constants_2018/equals_test.dart @@ -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 {