-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1205. Mixin methods equality tests added
- Loading branch information
sgrekhov
committed
Oct 5, 2021
1 parent
ebe9d70
commit 3f79167
Showing
5 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
LanguageFeatures/Constructor-tear-offs/equality_A07_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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. | ||
|
||
/// @assertion Test equality of function and methods tearoffs. | ||
/// https://github.com/dart-lang/language/issues/1712 | ||
/// | ||
/// @description Checks equality of non-generic mixin methods tearoffs | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
class A { | ||
int mixedInSuperMethod() => 0; | ||
} | ||
|
||
mixin M on A { | ||
void mixedInMethod() {} | ||
int mixedInSuperMethod() => super.mixedInSuperMethod() + 1; | ||
} | ||
|
||
class AM extends A with M { | ||
int Function() get tearoffSuperMethod => super.mixedInSuperMethod; | ||
} | ||
|
||
main() { | ||
A a = new A(); | ||
AM am = new AM(); | ||
|
||
var s1 = a.mixedInSuperMethod; | ||
var s2 = a.mixedInSuperMethod; | ||
var s3 = am.tearoffSuperMethod; | ||
var s4 = am.tearoffSuperMethod; | ||
|
||
Expect.equals(s1, s2); | ||
Expect.notEquals(s1, s3); | ||
Expect.notEquals(s2, s3); | ||
Expect.equals(s3, s4); | ||
Expect.equals(0, s1()); | ||
Expect.equals(1, s3()); | ||
|
||
A a1 = new AM(); | ||
var s5 = a1.mixedInSuperMethod; | ||
Expect.equals(s5, a1.mixedInSuperMethod); | ||
Expect.equals(1, s5()); | ||
} |
48 changes: 48 additions & 0 deletions
48
LanguageFeatures/Constructor-tear-offs/equality_A07_t02.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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. | ||
|
||
/// @assertion Test equality of function and methods tearoffs. | ||
/// https://github.com/dart-lang/language/issues/1712 | ||
/// | ||
/// @description Checks equality of generic mixin methods tearoffs | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
class A { | ||
T mixedInSuperMethod<T extends num>(T t) => t; | ||
} | ||
|
||
mixin M on A { | ||
void mixedInMethod<T>() {} | ||
T mixedInSuperMethod<T extends num>(T t) => super.mixedInSuperMethod<T>(t) + 1 as T; | ||
} | ||
|
||
class AM<T extends num> extends A with M { | ||
T Function(T t) get tearoffSuperMethod => super.mixedInSuperMethod<T>; | ||
} | ||
|
||
main() { | ||
A a = new A(); | ||
AM<int> am = new AM<int>(); | ||
|
||
var s1 = a.mixedInSuperMethod<int>; | ||
var s2 = a.mixedInSuperMethod<int>; | ||
var s3 = am.tearoffSuperMethod; | ||
var s4 = am.tearoffSuperMethod; | ||
|
||
Expect.equals(s1, s2); | ||
Expect.notEquals(s1, s3); | ||
Expect.notEquals(s2, s3); | ||
Expect.equals(s3, s4); | ||
Expect.equals(0, s1(0)); | ||
Expect.equals(1, s3(0)); | ||
|
||
A a1 = new AM<double>(); | ||
var s5 = a1.mixedInSuperMethod<double>; | ||
Expect.equals(s5, a1.mixedInSuperMethod<double>); | ||
Expect.approxEquals(4.14, s5(3.14)); | ||
} |
32 changes: 32 additions & 0 deletions
32
LanguageFeatures/Constructor-tear-offs/equality_A07_t03.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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. | ||
|
||
/// @assertion Test equality of function and methods tearoffs. | ||
/// https://github.com/dart-lang/language/issues/1712 | ||
/// | ||
/// @description Checks equality of generic mixin methods tearoffs | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
class A { | ||
T mixedInSuperMethod<T extends num>(T t) => t; | ||
} | ||
|
||
mixin M on A { | ||
void mixedInMethod<T>() {} | ||
T mixedInSuperMethod<T extends num>(T t) => super.mixedInSuperMethod<T>(t) + 1 as T; | ||
} | ||
|
||
main() { | ||
A a = new A(); | ||
var s1 = a.mixedInSuperMethod<int>; | ||
int Function(int) s2 = a.mixedInSuperMethod; | ||
|
||
Expect.equals(s1, s2); | ||
Expect.equals(s1, a.mixedInSuperMethod<int>); | ||
Expect.notEquals(s1, a.mixedInSuperMethod<num>); | ||
} |
50 changes: 50 additions & 0 deletions
50
LanguageFeatures/Constructor-tear-offs/equality_A07_t04.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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. | ||
|
||
/// @assertion Test equality of function and methods tearoffs. | ||
/// https://github.com/dart-lang/language/issues/1712 | ||
/// | ||
/// @description Checks equality of generic mixin methods tearoffs | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
typedef IntAlias = int; | ||
|
||
class A { | ||
T mixedInSuperMethod<T extends num>(T t) => t; | ||
} | ||
|
||
mixin M on A { | ||
void mixedInMethod<T>() {} | ||
T mixedInSuperMethod<T extends num>(T t) => super.mixedInSuperMethod<T>(t) + 1 as T; | ||
} | ||
|
||
class AM<T extends num> extends A with M { | ||
T Function(T t) get tearoffSuperMethod => super.mixedInSuperMethod<T>; | ||
} | ||
|
||
main() { | ||
A a = new A(); | ||
AM<IntAlias> am = new AM<IntAlias>(); | ||
|
||
var s1 = a.mixedInSuperMethod<int>; | ||
var s2 = a.mixedInSuperMethod<IntAlias>; | ||
var s3 = am.tearoffSuperMethod; | ||
var s4 = am.tearoffSuperMethod; | ||
|
||
Expect.equals(s1, s2); | ||
Expect.notEquals(s1, s3); | ||
Expect.notEquals(s2, s3); | ||
Expect.equals(s3, s4); | ||
Expect.equals(0, s1(0)); | ||
Expect.equals(1, s3(0)); | ||
|
||
A a1 = new AM<int>(); | ||
var s5 = a1.mixedInSuperMethod<int>; | ||
Expect.equals(s5, a1.mixedInSuperMethod<IntAlias>); | ||
Expect.approxEquals(43, s5(42)); | ||
} |
50 changes: 50 additions & 0 deletions
50
LanguageFeatures/Constructor-tear-offs/equality_A07_t05.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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. | ||
|
||
/// @assertion Test equality of function and methods tearoffs. | ||
/// https://github.com/dart-lang/language/issues/1712 | ||
/// | ||
/// @description Checks equality of generic mixin methods tearoffs | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
class A { | ||
T mixedInSuperMethod<T extends num>(T t) => t; | ||
} | ||
|
||
mixin M on A { | ||
void mixedInMethod<T>() {} | ||
T mixedInSuperMethod<T extends num>(T t) => super.mixedInSuperMethod<T>(t) + 1 as T; | ||
} | ||
|
||
class AM<T extends num> extends A with M { | ||
T Function(T t) get tearoffSuperMethod => super.mixedInSuperMethod<T>; | ||
} | ||
|
||
main() { | ||
<X extends num>(X x) { | ||
A a = new A(); | ||
AM<X> am = new AM<X>(); | ||
|
||
var s1 = a.mixedInSuperMethod<X>; | ||
var s2 = a.mixedInSuperMethod<X>; | ||
var s3 = am.tearoffSuperMethod; | ||
var s4 = am.tearoffSuperMethod; | ||
|
||
Expect.equals(s1, s2); | ||
Expect.notEquals(s1, s3); | ||
Expect.notEquals(s2, s3); | ||
Expect.equals(s3, s4); | ||
Expect.equals(0, s1(x)); | ||
Expect.equals(1, s3(x)); | ||
|
||
A a1 = new AM<X>(); | ||
var s5 = a1.mixedInSuperMethod<X>; | ||
Expect.equals(s5, a1.mixedInSuperMethod<X>); | ||
Expect.approxEquals(1, s5(x)); | ||
}<int>(0); | ||
} |