[tests] Add regression tests for #46568

Two different const functions should not be identical.

Change-Id: I3974574c8d0cb34b9cf886532c41e1a77ae632a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206422
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
diff --git a/tests/language/closure/regress46568_test.dart b/tests/language/closure/regress46568_test.dart
new file mode 100644
index 0000000..33e34b6
--- /dev/null
+++ b/tests/language/closure/regress46568_test.dart
@@ -0,0 +1,40 @@
+// 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.
+
+import 'package:expect/expect.dart';
+
+// Regression test for https://github.com/dart-lang/sdk/issues/46568.
+
+var genericTopLevelFunctionCallCount = 0;
+var genericStaticMethodCallCount = 0;
+
+T? genericTopLevelFunction<T>() {
+  genericTopLevelFunctionCallCount++;
+  return null;
+}
+
+class A {
+  static T? genericStaticMethod<T>() {
+    genericStaticMethodCallCount++;
+    return null;
+  }
+}
+
+const int? Function() cIntTopLevelFunction1 = genericTopLevelFunction;
+const int? Function() cIntStaticMethod1 = A.genericStaticMethod;
+
+void main() {
+  // Two different const generic function instantiations should not be
+  // canonicalized to the same value.
+  Expect.isFalse(identical(cIntTopLevelFunction1, cIntStaticMethod1));
+  Expect.notEquals(cIntTopLevelFunction1, cIntStaticMethod1);
+
+  cIntTopLevelFunction1();
+  Expect.equals(1, genericTopLevelFunctionCallCount);
+  Expect.equals(0, genericStaticMethodCallCount);
+
+  cIntStaticMethod1();
+  Expect.equals(1, genericTopLevelFunctionCallCount);
+  Expect.equals(1, genericStaticMethodCallCount);
+}
diff --git a/tests/language_2/closure/regress46568_test.dart b/tests/language_2/closure/regress46568_test.dart
new file mode 100644
index 0000000..1117775
--- /dev/null
+++ b/tests/language_2/closure/regress46568_test.dart
@@ -0,0 +1,42 @@
+// 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.
+
+// @dart = 2.9
+
+import 'package:expect/expect.dart';
+
+// Regression test for https://github.com/dart-lang/sdk/issues/46568.
+
+var genericTopLevelFunctionCallCount = 0;
+var genericStaticMethodCallCount = 0;
+
+T genericTopLevelFunction<T>() {
+  genericTopLevelFunctionCallCount++;
+  return null;
+}
+
+class A {
+  static T genericStaticMethod<T>() {
+    genericStaticMethodCallCount++;
+    return null;
+  }
+}
+
+const int Function() cIntTopLevelFunction1 = genericTopLevelFunction;
+const int Function() cIntStaticMethod1 = A.genericStaticMethod;
+
+void main() {
+  // Two different const generic function instantiations should not be
+  // canonicalized to the same value.
+  Expect.isFalse(identical(cIntTopLevelFunction1, cIntStaticMethod1));
+  Expect.notEquals(cIntTopLevelFunction1, cIntStaticMethod1);
+
+  cIntTopLevelFunction1();
+  Expect.equals(1, genericTopLevelFunctionCallCount);
+  Expect.equals(0, genericStaticMethodCallCount);
+
+  cIntStaticMethod1();
+  Expect.equals(1, genericTopLevelFunctionCallCount);
+  Expect.equals(1, genericStaticMethodCallCount);
+}