diff --git a/LanguageFeatures/Constructor-tear-offs/equality_A07_t01.dart b/LanguageFeatures/Constructor-tear-offs/equality_A07_t01.dart new file mode 100644 index 0000000000..ddb8df5f33 --- /dev/null +++ b/LanguageFeatures/Constructor-tear-offs/equality_A07_t01.dart @@ -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 sgrekhov@unipro.ru + +// 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()); +} diff --git a/LanguageFeatures/Constructor-tear-offs/equality_A07_t02.dart b/LanguageFeatures/Constructor-tear-offs/equality_A07_t02.dart new file mode 100644 index 0000000000..20adcf4de4 --- /dev/null +++ b/LanguageFeatures/Constructor-tear-offs/equality_A07_t02.dart @@ -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 sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=constructor-tearoffs + +import "../../Utils/expect.dart"; + +class A { + T mixedInSuperMethod(T t) => t; +} + +mixin M on A { + void mixedInMethod() {} + T mixedInSuperMethod(T t) => super.mixedInSuperMethod(t) + 1 as T; +} + +class AM extends A with M { + T Function(T t) 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(0)); + Expect.equals(1, s3(0)); + + A a1 = new AM(); + var s5 = a1.mixedInSuperMethod; + Expect.equals(s5, a1.mixedInSuperMethod); + Expect.approxEquals(4.14, s5(3.14)); +} diff --git a/LanguageFeatures/Constructor-tear-offs/equality_A07_t03.dart b/LanguageFeatures/Constructor-tear-offs/equality_A07_t03.dart new file mode 100644 index 0000000000..62347b09e7 --- /dev/null +++ b/LanguageFeatures/Constructor-tear-offs/equality_A07_t03.dart @@ -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 sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=constructor-tearoffs + +import "../../Utils/expect.dart"; + +class A { + T mixedInSuperMethod(T t) => t; +} + +mixin M on A { + void mixedInMethod() {} + T mixedInSuperMethod(T t) => super.mixedInSuperMethod(t) + 1 as T; +} + +main() { + A a = new A(); + var s1 = a.mixedInSuperMethod; + int Function(int) s2 = a.mixedInSuperMethod; + + Expect.equals(s1, s2); + Expect.equals(s1, a.mixedInSuperMethod); + Expect.notEquals(s1, a.mixedInSuperMethod); +} diff --git a/LanguageFeatures/Constructor-tear-offs/equality_A07_t04.dart b/LanguageFeatures/Constructor-tear-offs/equality_A07_t04.dart new file mode 100644 index 0000000000..fbfc924084 --- /dev/null +++ b/LanguageFeatures/Constructor-tear-offs/equality_A07_t04.dart @@ -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 sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=constructor-tearoffs + +import "../../Utils/expect.dart"; + +typedef IntAlias = int; + +class A { + T mixedInSuperMethod(T t) => t; +} + +mixin M on A { + void mixedInMethod() {} + T mixedInSuperMethod(T t) => super.mixedInSuperMethod(t) + 1 as T; +} + +class AM extends A with M { + T Function(T t) 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(0)); + Expect.equals(1, s3(0)); + + A a1 = new AM(); + var s5 = a1.mixedInSuperMethod; + Expect.equals(s5, a1.mixedInSuperMethod); + Expect.approxEquals(43, s5(42)); +} diff --git a/LanguageFeatures/Constructor-tear-offs/equality_A07_t05.dart b/LanguageFeatures/Constructor-tear-offs/equality_A07_t05.dart new file mode 100644 index 0000000000..c9bc321033 --- /dev/null +++ b/LanguageFeatures/Constructor-tear-offs/equality_A07_t05.dart @@ -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 sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=constructor-tearoffs + +import "../../Utils/expect.dart"; + +class A { + T mixedInSuperMethod(T t) => t; +} + +mixin M on A { + void mixedInMethod() {} + T mixedInSuperMethod(T t) => super.mixedInSuperMethod(t) + 1 as T; +} + +class AM extends A with M { + T Function(T t) get tearoffSuperMethod => super.mixedInSuperMethod; +} + +main() { + (X x) { + 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(x)); + Expect.equals(1, s3(x)); + + A a1 = new AM(); + var s5 = a1.mixedInSuperMethod; + Expect.equals(s5, a1.mixedInSuperMethod); + Expect.approxEquals(1, s5(x)); + }(0); +}