#3054. Add more test cases to closurization tests. Part 2. (#3069)
Add more test cases to closurization tests. Part 2.
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t01.dart
index 34499ba..8a71b41 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t01.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t01.dart
@@ -40,14 +40,46 @@
}
}
-main() {
- C o = C();
- final f = o.m;
- f.expectStaticType<
- Exactly<num Function<Y extends num>(int r1, Y r2, {int p1})>
- >();
+mixin M {
+ num m<Y extends num>(
+ covariant int r1,
+ covariant Y r2, {
+ covariant int p1 = 0
+ }) {
+ return 42;
+ }
+}
+class MO = Object with M;
+enum E {
+ e0;
+ num m<Y extends num>(
+ covariant int r1,
+ covariant Y r2, {
+ covariant int p1 = 0
+ }) {
+ return 42;
+ }
+}
+
+main() {
+ C c = C();
+ final fc = c.m;
+ fc.expectStaticType<
+ Exactly<num Function<Y extends num>(int r1, Y r2, {int p1})>>();
Expect.isTrue(
- f is num Function<Y extends num>(Object? r1, Object? r2, {Object? p1})
- );
+ fc is num Function<Y extends num>(Object? r1, Object? r2, {Object? p1}));
+
+ M m = MO();
+ final fm = m.m;
+ fm.expectStaticType<
+ Exactly<num Function<Y extends num>(int r1, Y r2, {int p1})>>();
+ Expect.isTrue(
+ fm is num Function<Y extends num>(Object? r1, Object? r2, {Object? p1}));
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<num Function<Y extends num>(int r1, Y r2, {int p1})>>();
+ Expect.isTrue(
+ fe is num Function<Y extends num>(Object? r1, Object? r2, {Object? p1}));
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t02.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t02.dart
index e1d6bfa..35426f2 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t02.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t02.dart
@@ -36,18 +36,130 @@
}
}
+mixin M<X> {
+ X m<Y extends X>(X r1, Y r2, {required X p1}) {
+ return 42 as X;
+ }
+}
+class MO<X> = Object with M<X>;
+
+enum E<X> {
+ e0;
+ X m<Y extends X>(X r1, Y r2, {required X p1}) {
+ return 42 as X;
+ }
+}
+
+class A<X> {}
+extension Ext<X> on A<X> {
+ X m<Y extends X>(X r1, Y r2, {required X p1}) {
+ return 42 as X;
+ }
+}
+
+extension type ET<X>(int _) {
+ X m<Y extends X>(X r1, Y r2, {required X p1}) {
+ return 42 as X;
+ }
+}
+
main() {
- C<Object?> o = C<Object?>();
- final f = o.m;
- f.expectStaticType<
- Exactly<Object? Function<Y extends Object?>(Object? r1, Y r2, {required Object? p1})>
+ C<Object?> c = C<Object?>();
+ final fc = c.m;
+ fc.expectStaticType<
+ Exactly<
+ Object? Function<Y extends Object?>(
+ Object? r1,
+ Y r2, {
+ required Object? p1,
+ })
+ >
>();
Expect.isTrue(
- f is Object? Function<Y extends Object?>( // ignore: unnecessary_type_check
+ fc is Object? Function<Y extends Object?>( // ignore: unnecessary_type_check
Object? r1,
Y r2, {
required Object? p1,
}),
);
+
+ M<Object?> m = MO<Object?>();
+ final fm = m.m;
+ fm.expectStaticType<
+ Exactly<
+ Object? Function<Y extends Object?>(
+ Object? r1,
+ Y r2, {
+ required Object? p1,
+ })
+ >
+ >();
+
+ Expect.isTrue(
+ fm is Object? Function<Y extends Object?>( // ignore: unnecessary_type_check
+ Object? r1,
+ Y r2, {
+ required Object? p1,
+ }),
+ );
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<
+ Object? Function<Y extends Object?>(
+ Object? r1,
+ Y r2, {
+ required Object? p1,
+ })
+ >
+ >();
+
+ Expect.isTrue(
+ fe is Object? Function<Y extends Object?>( // ignore: unnecessary_type_check
+ Object? r1,
+ Y r2, {
+ required Object? p1,
+ }),
+ );
+
+ A<Object?> a = A<Object?>();
+ final fa = a.m;
+ fa.expectStaticType<
+ Exactly<
+ Object? Function<Y extends Object?>(
+ Object? r1,
+ Y r2, {
+ required Object? p1,
+ })
+ >
+ >();
+
+ Expect.isTrue(
+ fa is Object? Function<Y extends Object?>( // ignore: unnecessary_type_check
+ Object? r1,
+ Y r2, {
+ required Object? p1,
+ }),
+ );
+
+ ET<Object?> et = ET<Object?>(0);
+ final fet = et.m;
+ fet.expectStaticType<
+ Exactly<
+ Object? Function<Y extends Object?>(
+ Object? r1,
+ Y r2, {
+ required Object? p1,
+ })
+ >
+ >();
+
+ Expect.isTrue(
+ fet is Object? Function<Y extends Object?>( // ignore: unnecessary_type_check
+ Object? r1,
+ Y r2, {
+ required Object? p1,
+ }),
+ );
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t03.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t03.dart
index 45ff25c..ea49ab3 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t03.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t03.dart
@@ -40,18 +40,59 @@
}
}
+mixin M<X extends num> {
+ X m<Y extends X>(
+ covariant X r1,
+ covariant Y r2, {
+ required covariant int p1,
+ }) {
+ return 42 as X;
+ }
+}
+class MO<X extends num> = Object with M<X>;
+
+enum E<X extends num> {
+ e0;
+ X m<Y extends X>(
+ covariant X r1,
+ covariant Y r2, {
+ required covariant int p1,
+ }) {
+ return 42 as X;
+ }
+}
+
main() {
- var o = C<num>();
- final f = o.m;
- f.expectStaticType<
+ var c = C<num>();
+ final fc = c.m;
+ fc.expectStaticType<
Exactly<num Function<Y extends num>(num r1, Y r2, {required int p1})>
>();
Expect.isTrue(
- f is num Function<Y extends num>(
- Object? r1,
- Object? r2, {
- required Object? p1,
+ fc is num Function<Y extends num>(Object? r1, Y r2, {required Object? p1,}),
+ );
+
+ M<num> m = MO<num>();
+ final fm = m.m;
+ fm.expectStaticType<
+ Exactly<num Function<Y extends num>(num r1, Y r2, {required int p1})>
+ >();
+
+ Expect.isTrue(
+ fm is num Function<Y extends num>(
+ Object? r1,
+ Object? r2, {
+ required Object? p1,
}),
);
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<num Function<Y extends num>(num r1, Y r2, {required int p1})>
+ >();
+
+ Expect.isTrue(
+ fe is num Function<Y extends num>(Object? r1, Y r2, {required Object? p1}),
+ );
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A04_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A04_t01.dart
index 0d7a99a..179ee39 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A04_t01.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A04_t01.dart
@@ -41,10 +41,37 @@
}
}
+mixin M {
+ Y m<X, Y extends num>(String r1, Y r2, r3, {X? p1, int p2 = 0, p3}) {
+ return 42 as Y;
+ }
+}
+class MO = Object with M;
+
+enum E {
+ e0;
+ Y m<X, Y extends num>(String r1, Y r2, r3, {X? p1, int p2 = 0, p3}) {
+ return 42 as Y;
+ }
+}
+
+class A {}
+extension Ext on A {
+ Y m<X, Y extends num>(String r1, Y r2, r3, {X? p1, int p2 = 0, p3}) {
+ return 42 as Y;
+ }
+}
+
+extension type ET(int _) {
+ Y m<X, Y extends num>(String r1, Y r2, r3, {X? p1, int p2 = 0, p3}) {
+ return 42 as Y;
+ }
+}
+
main() {
- var o = C();
- final f = o.m;
- f.expectStaticType<
+ var c = C();
+ final fc = c.m;
+ fc.expectStaticType<
Exactly<
Y Function<X, Y extends num>(
String r1,
@@ -56,9 +83,8 @@
})
>
>();
-
Expect.isTrue(
- f is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ fc is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
String r1,
Y r2,
dynamic r3, {
@@ -67,4 +93,103 @@
dynamic p3,
})
);
+
+ M m = MO();
+ final fm = m.m;
+ fm.expectStaticType<
+ Exactly<
+ Y Function<X, Y extends num>(
+ String r1,
+ Y r2,
+ dynamic r3, {
+ X? p1,
+ int p2,
+ dynamic p3,
+ })
+ >
+ >();
+ Expect.isTrue(
+ fm is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ String r1,
+ Y r2,
+ dynamic r3, {
+ X? p1,
+ int p2,
+ dynamic p3,
+ })
+ );
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<
+ Y Function<X, Y extends num>(
+ String r1,
+ Y r2,
+ dynamic r3, {
+ X? p1,
+ int p2,
+ dynamic p3,
+ })
+ >
+ >();
+ Expect.isTrue(
+ fe is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ String r1,
+ Y r2,
+ dynamic r3, {
+ X? p1,
+ int p2,
+ dynamic p3,
+ })
+ );
+
+ var a = A();
+ final fa = a.m;
+ fa.expectStaticType<
+ Exactly<
+ Y Function<X, Y extends num>(
+ String r1,
+ Y r2,
+ dynamic r3, {
+ X? p1,
+ int p2,
+ dynamic p3,
+ })
+ >
+ >();
+ Expect.isTrue(
+ fa is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ String r1,
+ Y r2,
+ dynamic r3, {
+ X? p1,
+ int p2,
+ dynamic p3,
+ })
+ );
+
+ var et = ET(0);
+ final fet = et.m;
+ fet.expectStaticType<
+ Exactly<
+ Y Function<X, Y extends num>(
+ String r1,
+ Y r2,
+ dynamic r3, {
+ X? p1,
+ int p2,
+ dynamic p3,
+ })
+ >
+ >();
+ Expect.isTrue(
+ fet is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ String r1,
+ Y r2,
+ dynamic r3, {
+ X? p1,
+ int p2,
+ dynamic p3,
+ })
+ );
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A05_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A05_t01.dart
index 6f4e9bc..ed96885 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A05_t01.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A05_t01.dart
@@ -50,10 +50,65 @@
}
}
+mixin M<Z extends String> {
+ List<Y> m<X, Y extends num>(
+ List<Z> r1,
+ List<Y> r2,
+ r3, {
+ List<X>? p1,
+ List<int> p2 = const [],
+ p3 = const [],
+ }) {
+ return <Y>[];
+ }
+}
+class MO<Z extends String> = Object with M<Z>;
+
+enum E<Z extends String> {
+ e0;
+ List<Y> m<X, Y extends num>(
+ List<Z> r1,
+ List<Y> r2,
+ r3, {
+ List<X>? p1,
+ List<int> p2 = const [],
+ p3 = const [],
+ }) {
+ return <Y>[];
+ }
+}
+
+class A<Z extends String>{}
+extension Ext<Z extends String> on A<Z> {
+ List<Y> m<X, Y extends num>(
+ List<Z> r1,
+ List<Y> r2,
+ r3, {
+ List<X>? p1,
+ List<int> p2 = const [],
+ p3 = const [],
+ }) {
+ return <Y>[];
+ }
+}
+
+extension type ET<Z extends String>(int _) {
+ List<Y> m<X, Y extends num>(
+ List<Z> r1,
+ List<Y> r2,
+ r3, {
+ List<X>? p1,
+ List<int> p2 = const [],
+ p3 = const [],
+ }) {
+ return <Y>[];
+ }
+}
+
main() {
- var o = C<String>();
- final f = o.m;
- f.expectStaticType<
+ var c = C<String>();
+ final fc = c.m;
+ fc.expectStaticType<
Exactly<
List<Y> Function<X, Y extends num>(
List<String> r1,
@@ -65,9 +120,8 @@
})
>
>();
-
Expect.isTrue(
- f is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
+ fc is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
List<String> r1,
List<Y> r2,
dynamic r3, {
@@ -76,4 +130,103 @@
dynamic p3,
})
);
+
+ M<String> m = MO<String>();
+ final fm = m.m;
+ fc.expectStaticType<
+ Exactly<
+ List<Y> Function<X, Y extends num>(
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, {
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ })
+ >
+ >();
+ Expect.isTrue(
+ fm is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, {
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ })
+ );
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<
+ List<Y> Function<X, Y extends num>(
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, {
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ })
+ >
+ >();
+ Expect.isTrue(
+ fe is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, {
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ })
+ );
+
+ var a = A<String>();
+ final fa = a.m;
+ fa.expectStaticType<
+ Exactly<
+ List<Y> Function<X, Y extends num>(
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, {
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ })
+ >
+ >();
+ Expect.isTrue(
+ fa is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, {
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ })
+ );
+
+ var et = ET<String>(0);
+ final fet = et.m;
+ fet.expectStaticType<
+ Exactly<
+ List<Y> Function<X, Y extends num>(
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, {
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ })
+ >
+ >();
+ Expect.isTrue(
+ fet is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, {
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ })
+ );
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A06_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A06_t01.dart
index fe8b9da..1748fa5 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A06_t01.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A06_t01.dart
@@ -36,13 +36,34 @@
num m(int r1, {String p1 = ""}) => r1;
}
-main() {
- C o1 = C();
- C o2 = C();
- final f1 = o1.m;
- final f2 = o1.m;
- final f3 = o2.m;
+mixin M {
+ num m(int r1, {covariant String p1 = ""}) => r1;
+}
+class MO = Object with M;
- Expect.equals(f1, f2);
- Expect.notEquals(f1, f3);
+enum E {
+ e0, e1;
+ num m(int r1, {required String p1}) => r1;
+}
+
+main() {
+ C c = C();
+ final fc1 = c.m;
+ final fc2 = c.m;
+ final fc3 = C().m;
+ Expect.equals(fc1, fc2);
+ Expect.notEquals(fc1, fc3);
+
+ M m = MO();
+ final fm1 = m.m;
+ final fm2 = m.m;
+ final fm3 = MO().m;
+ Expect.equals(fm1, fm2);
+ Expect.notEquals(fm1, fm3);
+
+ final fe1 = E.e0.m;
+ final fe2 = E.e0.m;
+ final fe3 = E.e1.m;
+ Expect.equals(fe1, fe2);
+ Expect.notEquals(fe1, fe3);
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A06_t02.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A06_t02.dart
new file mode 100644
index 0000000..4431adc
--- /dev/null
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A06_t02.dart
@@ -0,0 +1,59 @@
+// Copyright (c) 2025, 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 Let `o` be an object, and let `u` be a fresh final variable bound
+/// to o. The closurization of method `f` on object `o` is defined to be
+/// equivalent to:
+/// ```
+/// - <X1 extends B′1, ..., Xs extends B′s>
+/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) =>
+/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k);
+/// ```
+/// where `f` is an instance method named `m` which has type parameter
+/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters
+/// `p1, ..., pn`, and named parameters `pn+1, ..., pn+k` with defaults
+/// `d1, ..., dk`, using `null` for parameters whose default value is not
+/// specified.
+/// ...
+/// There is one way in which the function object yielded by the instance
+/// method closurization differs from the function object obtained by function
+/// closurization on the above mentioned function literal: Assume that `o1` and
+/// `o2` are objects, `m` is an identifier, and `c1` and `c2` are function
+/// objects obtained by closurization of `m` on `o1` respectively `o2`. Then
+/// `c1 == c2` evaluates to `true` if and only if `o1` and `o2` is the same
+/// object.
+///
+/// @description Check that if `o1` and `o2` are objects, `m` is an identifier,
+/// and `c1` and `c2` are function objects obtained by closurization of `m` on
+/// `o1` respectively `o2`, then `c1 == c2` evaluates to `false` if `o1` and
+/// `o2` are extensions or extension types.
+/// @author sgrekhov22@gmail.com
+/// @issue 60065
+
+import '../../../../Utils/expect.dart';
+
+class A {}
+extension Ext on A {
+ num m(int r1, {String p1 = ""}) => r1;
+}
+
+extension type ET(int _) {
+ num m(int r1, {p1 = ""}) => r1;
+}
+
+main() {
+ A a = A();
+ final fa1 = a.m;
+ final fa2 = a.m;
+ // For extensions and extension types, fa1 != fa2. However, the implementation
+ // may have an optimization that makes fa1 identical to fa2, in which case
+ // fa1 == fa2. Therefore, we allow both results and check that the == operator
+ // on these functions does not throw an exception
+ Expect.isTrue(fa1 == fa2 || fa1 != fa2);
+
+ ET et = ET(0);
+ final fet1 = et.m;
+ final fet2 = et.m;
+ Expect.isTrue(fet1 == fet2 || fet1 != fet2);
+}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t01.dart
index ae0319a..d71d264 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t01.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t01.dart
@@ -41,14 +41,52 @@
}
}
+mixin M {
+ num m<Y extends num>(
+ covariant int r1,
+ covariant Y r2, [
+ covariant int p1 = 0,
+ ]) {
+ return 42;
+ }
+}
+class MO = Object with M;
+
+enum E {
+ e0;
+ num m<Y extends num>(
+ covariant int r1,
+ covariant Y r2, [
+ covariant int p1 = 0,
+ ]) {
+ return 42;
+ }
+}
+
main() {
- C o = C();
- final f = o.m;
- f.expectStaticType<
+ C c = C();
+ final fc = c.m;
+ fc.expectStaticType<
Exactly<num Function<Y extends num>(int r1, Y r2, [int p1])>
>();
-
Expect.isTrue(
- f is num Function<Y extends num>(Object? r1, Object? r2, [Object? p1]),
+ fc is num Function<Y extends num>(Object? r1, Object? r2, [Object? p1]),
+ );
+
+ M m = MO();
+ final fm = m.m;
+ fm.expectStaticType<
+ Exactly<num Function<Y extends num>(int r1, Y r2, [int p1])>
+ >();
+ Expect.isTrue(
+ fm is num Function<Y extends num>(Object? r1, Object? r2, [Object? p1]),
+ );
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<num Function<Y extends num>(int r1, Y r2, [int p1])>
+ >();
+ Expect.isTrue(
+ fe is num Function<Y extends num>(Object? r1, Object? r2, [Object? p1]),
);
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t02.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t02.dart
index f567104..2c14e5d 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t02.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t02.dart
@@ -37,16 +37,85 @@
}
}
+mixin M<X> {
+ X m<Y extends X>(X r1, Y r2, [X? p1]) {
+ return 42 as X;
+ }
+}
+class MO<X> = Object with M<X>;
+
+enum E<X> {
+ e0;
+ X m<Y extends X>(X r1, Y r2, [X? p1]) {
+ return 42 as X;
+ }
+}
+
+class A<X> {}
+extension Ext<X> on A<X> {
+ X m<Y extends X>(X r1, Y r2, [X? p1]) {
+ return 42 as X;
+ }
+}
+
+extension type ET<X>(int _) {
+ X m<Y extends X>(X r1, Y r2, [X? p1]) {
+ return 42 as X;
+ }
+}
+
main() {
- C<Object?> o = C<Object?>();
- final f = o.m;
- f.expectStaticType<
+ C<Object?> c = C<Object?>();
+ final fc = c.m;
+ fc.expectStaticType<
Exactly<
Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1])
>
>();
-
Expect.isTrue(
- f is Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1]) // ignore: unnecessary_type_check
+ fc is Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1]) // ignore: unnecessary_type_check
+ );
+
+ M<Object?> m = MO<Object?>();
+ final fm = m.m;
+ fm.expectStaticType<
+ Exactly<
+ Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1])
+ >
+ >();
+ Expect.isTrue(
+ fm is Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1]) // ignore: unnecessary_type_check
+ );
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<
+ Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1])
+ >
+ >();
+ Expect.isTrue(
+ fe is Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1]) // ignore: unnecessary_type_check
+ );
+
+ A<Object?> a = A<Object?>();
+ final fa = a.m;
+ fa.expectStaticType<
+ Exactly<
+ Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1])
+ >
+ >();
+ Expect.isTrue(
+ fa is Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1]) // ignore: unnecessary_type_check
+ );
+
+ ET<Object?> et = ET<Object?>(0);
+ final fet = et.m;
+ fet.expectStaticType<
+ Exactly<
+ Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1])
+ >
+ >();
+ Expect.isTrue(
+ fet is Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1]) // ignore: unnecessary_type_check
);
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t03.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t03.dart
index 1dead7c..74adc47 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t03.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t03.dart
@@ -37,13 +37,41 @@
}
}
+mixin M<X extends num> {
+ X m<Y extends X>(covariant X r1, covariant Y r2, [covariant int? p1]) {
+ return 42 as X;
+ }
+}
+class MO<X extends num> = Object with M<X>;
+
+enum E<X extends num> {
+ e0;
+ X m<Y extends X>(covariant X r1, covariant Y r2, [covariant int? p1]) {
+ return 42 as X;
+ }
+}
+
main() {
- var o = C<num>();
- final f = o.m;
- f.expectStaticType<
+ var c = C<num>();
+ final fc = c.m;
+ fc.expectStaticType<
Exactly<num Function<Y extends num>(num r1, Y r2, [int? p1])>
>();
-
Expect.isTrue(
- f is num Function<Y extends num>(Object? r1, Object? r2, [Object? p1]));
+ fc is num Function<Y extends num>(Object? r1, Y r2, [Object? p1]));
+
+ M<num> m = MO<num>();
+ final fm = m.m;
+ fm.expectStaticType<
+ Exactly<num Function<Y extends num>(num r1, Y r2, [int? p1])>
+ >();
+ Expect.isTrue(
+ fm is num Function<Y extends num>(Object? r1, Y r2, [Object? p1]));
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<num Function<Y extends num>(num r1, Y r2, [int? p1])>
+ >();
+ Expect.isTrue(
+ fe is num Function<Y extends num>(Object? r1, Y r2, [Object? p1]));
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A04_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A04_t01.dart
index 25e362a..1b0834e 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A04_t01.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A04_t01.dart
@@ -42,10 +42,37 @@
}
}
+mixin M {
+ Y m<X, Y extends num>(String r1, Y r2, r3, [X? p1, int p2 = 0, p3]) {
+ return 42 as Y;
+ }
+}
+class MO = Object with M;
+
+enum E {
+ e0;
+ Y m<X, Y extends num>(String r1, Y r2, r3, [X? p1, int p2 = 0, p3]) {
+ return 42 as Y;
+ }
+}
+
+class A {}
+extension Ext on A {
+ Y m<X, Y extends num>(String r1, Y r2, r3, [X? p1, int p2 = 0, p3]) {
+ return 42 as Y;
+ }
+}
+
+extension type ET(int _) {
+ Y m<X, Y extends num>(String r1, Y r2, r3, [X? p1, int p2 = 0, p3]) {
+ return 42 as Y;
+ }
+}
+
main() {
- var o = C();
- final f = o.m;
- f.expectStaticType<
+ var c = C();
+ final fc = c.m;
+ fc.expectStaticType<
Exactly<
Y Function<X, Y extends num>(
String r1,
@@ -57,9 +84,8 @@
])
>
>();
-
Expect.isTrue(
- f is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ fc is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
String r1,
Y r2,
dynamic r3, [
@@ -68,4 +94,103 @@
dynamic p3,
])
);
+
+ M m = MO();
+ final fm = m.m;
+ fm.expectStaticType<
+ Exactly<
+ Y Function<X, Y extends num>(
+ String r1,
+ Y r2,
+ dynamic r3, [
+ X? p1,
+ int p2,
+ dynamic p3,
+ ])
+ >
+ >();
+ Expect.isTrue(
+ fm is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ String r1,
+ Y r2,
+ dynamic r3, [
+ X? p1,
+ int p2,
+ dynamic p3,
+ ])
+ );
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<
+ Y Function<X, Y extends num>(
+ String r1,
+ Y r2,
+ dynamic r3, [
+ X? p1,
+ int p2,
+ dynamic p3,
+ ])
+ >
+ >();
+ Expect.isTrue(
+ fe is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ String r1,
+ Y r2,
+ dynamic r3, [
+ X? p1,
+ int p2,
+ dynamic p3,
+ ])
+ );
+
+ var a = A();
+ final fa = a.m;
+ fa.expectStaticType<
+ Exactly<
+ Y Function<X, Y extends num>(
+ String r1,
+ Y r2,
+ dynamic r3, [
+ X? p1,
+ int p2,
+ dynamic p3,
+ ])
+ >
+ >();
+ Expect.isTrue(
+ fa is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ String r1,
+ Y r2,
+ dynamic r3, [
+ X? p1,
+ int p2,
+ dynamic p3,
+ ])
+ );
+
+ var et = ET(0);
+ final fet = et.m;
+ fet.expectStaticType<
+ Exactly<
+ Y Function<X, Y extends num>(
+ String r1,
+ Y r2,
+ dynamic r3, [
+ X? p1,
+ int p2,
+ dynamic p3,
+ ])
+ >
+ >();
+ Expect.isTrue(
+ fet is Y Function<X, Y extends num>( // ignore: unnecessary_type_check
+ String r1,
+ Y r2,
+ dynamic r3, [
+ X? p1,
+ int p2,
+ dynamic p3,
+ ])
+ );
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A05_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A05_t01.dart
index 9c878db..bb8b812 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A05_t01.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A05_t01.dart
@@ -51,10 +51,65 @@
}
}
+mixin M<Z extends String> {
+ List<Y> m<X, Y extends num>(
+ List<Z> r1,
+ List<Y> r2,
+ r3, [
+ List<X>? p1,
+ List<int> p2 = const [],
+ p3 = const [],
+ ]) {
+ return <Y>[];
+ }
+}
+class MO<Z extends String> = Object with M<Z>;
+
+enum E<Z extends String> {
+ e0;
+ List<Y> m<X, Y extends num>(
+ List<Z> r1,
+ List<Y> r2,
+ r3, [
+ List<X>? p1,
+ List<int> p2 = const [],
+ p3 = const [],
+ ]) {
+ return <Y>[];
+ }
+}
+
+class A<Z extends String> {}
+extension Ext<Z extends String> on A<Z> {
+ List<Y> m<X, Y extends num>(
+ List<Z> r1,
+ List<Y> r2,
+ r3, [
+ List<X>? p1,
+ List<int> p2 = const [],
+ p3 = const [],
+ ]) {
+ return <Y>[];
+ }
+}
+
+extension type ET<Z extends String>(int _) {
+ List<Y> m<X, Y extends num>(
+ List<Z> r1,
+ List<Y> r2,
+ r3, [
+ List<X>? p1,
+ List<int> p2 = const [],
+ p3 = const [],
+ ]) {
+ return <Y>[];
+ }
+}
+
main() {
- var o = C<String>();
- final f = o.m;
- f.expectStaticType<
+ var c = C<String>();
+ final fc = c.m;
+ fc.expectStaticType<
Exactly<
List<Y> Function<X, Y extends num>(
List<String> r1,
@@ -66,9 +121,8 @@
])
>
>();
-
Expect.isTrue(
- f is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
+ fc is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
List<String> r1,
List<Y> r2,
dynamic r3, [
@@ -77,4 +131,78 @@
dynamic p3,
])
);
+
+ M<String> m = MO<String>();
+ final fm = m.m;
+ fm.expectStaticType<
+ Exactly<
+ List<Y> Function<X, Y extends num>(
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, [
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ ])
+ >
+ >();
+ Expect.isTrue(
+ fm is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, [
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ ])
+ );
+
+ final fe = E.e0.m;
+ fe.expectStaticType<
+ Exactly<
+ List<Y> Function<X, Y extends num>(
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, [
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ ])
+ >
+ >();
+ Expect.isTrue(
+ fe is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, [
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ ])
+ );
+
+ var et = ET<String>(0);
+ final fet = et.m;
+ fet.expectStaticType<
+ Exactly<
+ List<Y> Function<X, Y extends num>(
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, [
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ ])
+ >
+ >();
+ Expect.isTrue(
+ fet is List<Y> Function<X, Y extends num>( // ignore: unnecessary_type_check
+ List<String> r1,
+ List<Y> r2,
+ dynamic r3, [
+ List<X>? p1,
+ List<int> p2,
+ dynamic p3,
+ ])
+ );
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A06_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A06_t01.dart
index 988dcd1..9aa0056 100644
--- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A06_t01.dart
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A06_t01.dart
@@ -37,13 +37,34 @@
num m(int r1, [String p1 = ""]) => r1;
}
-main() {
- C o1 = C();
- C o2 = C();
- final f1 = o1.m;
- final f2 = o1.m;
- final f3 = o2.m;
+mixin M {
+ num m(int r1, [covariant String p1 = ""]) => r1;
+}
+class MO = Object with M;
- Expect.equals(f1, f2);
- Expect.notEquals(f1, f3);
+enum E {
+ e0, e1;
+ num m(int r1, [String? p1]) => r1;
+}
+
+main() {
+ C c = C();
+ final fc1 = c.m;
+ final fc2 = c.m;
+ final fc3 = C().m;
+ Expect.equals(fc1, fc2);
+ Expect.notEquals(fc1, fc3);
+
+ M m = MO();
+ final fm1 = m.m;
+ final fm2 = m.m;
+ final fm3 = MO().m;
+ Expect.equals(fm1, fm2);
+ Expect.notEquals(fm1, fm3);
+
+ final fe1 = E.e0.m;
+ final fe2 = E.e0.m;
+ final fe3 = E.e1.m;
+ Expect.equals(fe1, fe2);
+ Expect.notEquals(fe1, fe3);
}
diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A06_t02.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A06_t02.dart
new file mode 100644
index 0000000..cb79950
--- /dev/null
+++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A06_t02.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2025, 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 Let `o` be an object, and let `u` be a fresh final variable bound
+/// to o. The closurization of method `f` on object `o` is defined to be
+/// equivalent to:
+/// ...
+/// ```
+/// - <X1 extends B′1, ..., Xs extends B′s>
+/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) =>
+/// u.m<X1, ..., Xs>(p1, ..., pn+k);
+/// ```
+/// where `f` is an instance method named `m` which has type parameter
+/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters
+/// `p1, ..., pn`, and optional positional parameters `pn+1, ..., pn+k` with
+/// defaults `d1, ..., dk`, using `null` for parameters whose default value is
+/// not specified.
+/// ...
+/// There is one way in which the function object yielded by the instance
+/// method closurization differs from the function object obtained by function
+/// closurization on the above mentioned function literal: Assume that `o1` and
+/// `o2` are objects, `m` is an identifier, and `c1` and `c2` are function
+/// objects obtained by closurization of `m` on `o1` respectively `o2`. Then
+/// `c1 == c2` evaluates to `true` if and only if `o1` and `o2` is the same
+/// object.
+///
+/// @description Check that if `o1` and `o2` are objects, `m` is an identifier,
+/// and `c1` and `c2` are function objects obtained by closurization of `m` on
+/// `o1` respectively `o2`, then `c1 == c2` evaluates to `false` if `o1` and
+/// `o2` are extensions or extension types.
+/// @author sgrekhov22@gmail.com
+/// @issue 60065
+
+import '../../../../Utils/expect.dart';
+
+class A {}
+extension Ext on A {
+ num m(int r1, [String p1 = ""]) => r1;
+}
+
+extension type ET(int _) {
+ num m(int r1, [p1 = ""]) => r1;
+}
+
+main() {
+ A a = A();
+ final fa1 = a.m;
+ final fa2 = a.m;
+ // For extensions and extension types, fa1 != fa2. However, the implementation
+ // may have an optimization that makes fa1 identical to fa2, in which case
+ // fa1 == fa2. Therefore, we allow both results and check that the == operator
+ // on these functions does not throw an exception
+ Expect.isTrue(fa1 == fa2 || fa1 != fa2);
+
+ ET et = ET(0);
+ final fet1 = et.m;
+ final fet2 = et.m;
+ Expect.isTrue(fet1 == fet2 || fet1 != fet2);
+}