mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
[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>
This commit is contained in:
parent
8cfb874b91
commit
9c6b1ea4e9
2 changed files with 82 additions and 0 deletions
40
tests/language/closure/regress46568_test.dart
Normal file
40
tests/language/closure/regress46568_test.dart
Normal file
|
@ -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);
|
||||
}
|
42
tests/language_2/closure/regress46568_test.dart
Normal file
42
tests/language_2/closure/regress46568_test.dart
Normal file
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue