From 9c6b1ea4e9b0344fffc9f6ee0e41eb27abf35c99 Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Mon, 19 Jul 2021 21:49:49 +0000 Subject: [PATCH] [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 Commit-Queue: Nicholas Shahan --- tests/language/closure/regress46568_test.dart | 40 ++++++++++++++++++ .../language_2/closure/regress46568_test.dart | 42 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 tests/language/closure/regress46568_test.dart create mode 100644 tests/language_2/closure/regress46568_test.dart diff --git a/tests/language/closure/regress46568_test.dart b/tests/language/closure/regress46568_test.dart new file mode 100644 index 00000000000..33e34b6207d --- /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() { + genericTopLevelFunctionCallCount++; + return null; +} + +class A { + static T? genericStaticMethod() { + 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 00000000000..1117775817d --- /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() { + genericTopLevelFunctionCallCount++; + return null; +} + +class A { + static T genericStaticMethod() { + 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); +}