Skip to content

Commit 167cd02

Browse files
eernstgcommit-bot@chromium.org
authored andcommitted
Restore function object equality related tests
This CL restores the equality related tests in tests/language/closure/identity_equality_tearoff_test.dart that we had in https://dart-review.googlesource.com/c/sdk/+/202243, but removed in order to finalize language team discussions about equality of function objects, based on language issue #1712. Note that these additional test cases do not include any cases involving tearoffs of extension methods, they will be dealt with separately. Change-Id: I84daaf91229bd0d0f4c64446bb71cb87f32eedfc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205081 Commit-Queue: Erik Ernst <[email protected]> Reviewed-by: Lasse R.H. Nielsen <[email protected]>
1 parent f77f8e5 commit 167cd02

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

tests/language/closure/identity_equality_tearoff_test.dart

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ class A {
4040

4141
void instanceMethod() {}
4242
X? genericInstanceMethod<X>() => null;
43+
44+
// Enable a mixed-in method in `M` that has a superinvocation.
45+
int mixedInSuperMethod() => 0;
46+
}
47+
48+
mixin M on A {
49+
void mixedInMethod() {}
50+
int mixedInSuperMethod() => super.mixedInSuperMethod() + 1;
51+
}
52+
53+
class AM extends A with M {
54+
int Function() get tearoffSuperMethod => super.mixedInSuperMethod;
55+
}
56+
57+
class AMM extends AM with M {
58+
// Tear off the second copy of M.mixedInSuperMethod
59+
// (`tearoffSuperMethod` still tears off the first copy).
60+
int Function() get tearoffSuperMethodSecond => super.mixedInSuperMethod;
61+
// In this case, `super.` should not make a difference.
62+
int Function() get tearoffSuperMethodSecondNoSuper => mixedInSuperMethod;
4363
}
4464

4565
const cTopLevelFunction = topLevelFunction;
@@ -104,6 +124,7 @@ void main() {
104124
checkIdentical(cIntStaticMethod1, vIntStaticMethod2);
105125
checkIdentical(vIntTopLevelFunction1, vIntTopLevelFunction2);
106126
checkIdentical(vIntStaticMethod1, vIntStaticMethod2);
127+
checkEqual(vIntInstanceMethod1, vIntInstanceMethod2);
107128

108129
const CheckIdentical(topLevelFunction, topLevelFunction);
109130
const CheckIdentical(A.staticMethod, A.staticMethod);
@@ -268,6 +289,56 @@ void main() {
268289
const CheckNotIdentical(cIntTopLevelFunction1, cStringTopLevelFunction);
269290
const CheckNotIdentical(cIntStaticMethod1, cStringStaticMethod);
270291

292+
{
293+
var am = AM();
294+
void Function() vMixedInMethod1 = am.mixedInMethod;
295+
void Function() vMixedInMethod2 = am.mixedInMethod;
296+
int Function() vMixedInSuperMethod1 = am.mixedInSuperMethod;
297+
int Function() vMixedInSuperMethod2 = am.mixedInSuperMethod;
298+
299+
checkEqual(am.mixedInMethod, am.mixedInMethod);
300+
checkEqual(vMixedInMethod1, vMixedInMethod2);
301+
checkEqual(am.mixedInSuperMethod, am.mixedInSuperMethod);
302+
checkEqual(vMixedInSuperMethod1, vMixedInSuperMethod2);
303+
}
304+
{
305+
var amm = AMM();
306+
void Function() vMixedInMethod1 = amm.mixedInMethod;
307+
void Function() vMixedInMethod2 = amm.mixedInMethod;
308+
int Function() vMixedInSuperMethod1 = amm.tearoffSuperMethod;
309+
int Function() vMixedInSuperMethod2 = amm.tearoffSuperMethod;
310+
int Function() vMixedInSuperMethodSecond1 = amm.tearoffSuperMethodSecond;
311+
int Function() vMixedInSuperMethodSecond2 = amm.tearoffSuperMethodSecond;
312+
int Function() vMixedInSuperMethodSecondNoSuper1 =
313+
amm.tearoffSuperMethodSecondNoSuper;
314+
int Function() vMixedInSuperMethodSecondNoSuper2 =
315+
amm.tearoffSuperMethodSecondNoSuper;
316+
317+
checkEqual(amm.mixedInMethod, amm.mixedInMethod);
318+
checkEqual(vMixedInMethod1, vMixedInMethod2);
319+
320+
checkEqual(amm.tearoffSuperMethod, amm.tearoffSuperMethod);
321+
checkEqual(vMixedInSuperMethod1, vMixedInSuperMethod2);
322+
checkEqual(amm.tearoffSuperMethodSecond, amm.tearoffSuperMethodSecond);
323+
checkEqual(vMixedInSuperMethodSecond1, vMixedInSuperMethodSecond2);
324+
checkUnequal(amm.tearoffSuperMethod, amm.tearoffSuperMethodSecond);
325+
checkUnequal(vMixedInSuperMethod1, vMixedInSuperMethodSecond2);
326+
checkUnequal(amm.tearoffSuperMethodSecond, amm.tearoffSuperMethod);
327+
checkUnequal(vMixedInSuperMethodSecond1, vMixedInSuperMethod2);
328+
329+
checkEqual(amm.tearoffSuperMethodSecondNoSuper,
330+
amm.tearoffSuperMethodSecondNoSuper);
331+
checkEqual(
332+
vMixedInSuperMethodSecondNoSuper1, vMixedInSuperMethodSecondNoSuper2);
333+
checkUnequal(amm.tearoffSuperMethod, amm.tearoffSuperMethodSecondNoSuper);
334+
checkUnequal(vMixedInSuperMethod1, vMixedInSuperMethodSecondNoSuper2);
335+
checkUnequal(amm.tearoffSuperMethodSecondNoSuper, amm.tearoffSuperMethod);
336+
checkUnequal(vMixedInSuperMethodSecondNoSuper1, vMixedInSuperMethod2);
337+
338+
checkEqual(
339+
amm.tearoffSuperMethodSecond, amm.tearoffSuperMethodSecondNoSuper);
340+
}
341+
271342
<X>() {
272343
X? Function() vXTopLevelFunction1 = genericTopLevelFunction;
273344
X? Function() vXStaticMethod1 = A.genericStaticMethod;
@@ -276,6 +347,14 @@ void main() {
276347
X? Function() vXInstanceMethod1 = a.genericInstanceMethod;
277348
X? Function() vXInstanceMethod2 = a.genericInstanceMethod;
278349

350+
checkEqual(vXTopLevelFunction1, vXTopLevelFunction2);
351+
checkEqual(vXStaticMethod1, vXStaticMethod2);
352+
checkEqual(vXInstanceMethod1, vXInstanceMethod2);
353+
354+
checkEqual(vXTopLevelFunction1, vIntTopLevelFunction1);
355+
checkEqual(vXStaticMethod1, vIntStaticMethod1);
356+
checkEqual(vXInstanceMethod1, vIntInstanceMethod2);
357+
279358
checkUnequal(vXTopLevelFunction1, vXStaticMethod1);
280359
checkUnequal(vXTopLevelFunction1, vXInstanceMethod1);
281360
checkUnequal(vXStaticMethod1, vXInstanceMethod1);

0 commit comments

Comments
 (0)