From 48506bc01ddc26c9713e517a132a4e84e800472e Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Tue, 28 Jan 2025 14:14:04 +0200 Subject: [PATCH 1/2] #3054. Add covariant parameters tests --- ...od_closurization_named_params_A03_t01.dart | 53 +++++++++++++++++ ...od_closurization_named_params_A03_t02.dart | 53 +++++++++++++++++ ...od_closurization_named_params_A03_t03.dart | 57 +++++++++++++++++++ ...osurization_positional_params_A03_t01.dart | 54 ++++++++++++++++++ ...osurization_positional_params_A03_t02.dart | 52 +++++++++++++++++ ...osurization_positional_params_A03_t03.dart | 49 ++++++++++++++++ 6 files changed, 318 insertions(+) create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t01.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t02.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t03.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t01.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t02.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t03.dart 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 new file mode 100644 index 0000000000..34499ba79b --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t01.dart @@ -0,0 +1,53 @@ +// 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: +/// ``` +/// - +/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) => +/// u.m(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. +/// ... +/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the +/// method declaration `D` be the implementation of `m` which is invoked by the +/// expression in the body. Let `T` be the class that contains D. +/// +/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is +/// the built-in class `Object`. +/// +/// @description Check that if `pj` is covariant then `Tj` is `Object?` at +/// run time. Test covariant-by-declaration parameters. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/expect.dart'; +import '../../../../Utils/static_type_helper.dart'; + +class C { + num m( + covariant int r1, + covariant Y r2, { + covariant int p1 = 0 + }) { + return 42; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType< + Exactly(int r1, Y r2, {int p1})> + >(); + + Expect.isTrue( + f is num Function(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 new file mode 100644 index 0000000000..a793c7d79a --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t02.dart @@ -0,0 +1,53 @@ +// 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: +/// ``` +/// - +/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) => +/// u.m(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. +/// ... +/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the +/// method declaration `D` be the implementation of `m` which is invoked by the +/// expression in the body. Let `T` be the class that contains D. +/// +/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is +/// the built-in class `Object`. +/// +/// @description Check that if `pj` is covariant then `Tj` is `Object?` at +/// run time. Test covariant-by-class parameters. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/expect.dart'; +import '../../../../Utils/static_type_helper.dart'; + +class C { + X m(X r1, Y r2, {required X p1}) { + return 42 as X; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType< + Exactly(Object? r1, Y r2, {required Object? p1})> + >(); + + Expect.isTrue( + f is Object? Function( // 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 new file mode 100644 index 0000000000..9a5fec6b41 --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_t03.dart @@ -0,0 +1,57 @@ +// 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: +/// ``` +/// - +/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) => +/// u.m(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. +/// ... +/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the +/// method declaration `D` be the implementation of `m` which is invoked by the +/// expression in the body. Let `T` be the class that contains D. +/// +/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is +/// the built-in class `Object`. +/// +/// @description Check that if `pj` is covariant then `Tj` is `Object?` at +/// run time. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/expect.dart'; +import '../../../../Utils/static_type_helper.dart'; + +class C { + X m( + covariant X r1, + covariant Y r2, { + required covariant int p1, + }) { + return 42 as X; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType< + Exactly(num r1, Y r2, {required int p1})> + >(); + + Expect.isTrue( + f is num Function( + Object? r1, + Object? r2, { + required Object? p1, + }), + ); +} 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 new file mode 100644 index 0000000000..ae0319a2e1 --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t01.dart @@ -0,0 +1,54 @@ +// 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: +/// ... +/// ``` +/// - +/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => +/// u.m(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. +/// ... +/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the +/// method declaration `D` be the implementation of `m` which is invoked by the +/// expression in the body. Let `T` be the class that contains D. +/// +/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is +/// the built-in class `Object`. +/// +/// @description Check that if `pj` is covariant then `Tj` is `Object?` at +/// run time. Test covariant-by-declaration parameters. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/expect.dart'; +import '../../../../Utils/static_type_helper.dart'; + +class C { + num m( + covariant int r1, + covariant Y r2, [ + covariant int p1 = 0, + ]) { + return 42; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType< + Exactly(int r1, Y r2, [int p1])> + >(); + + Expect.isTrue( + f is num Function(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 new file mode 100644 index 0000000000..fa0a606baf --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t02.dart @@ -0,0 +1,52 @@ +// 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: +/// ... +/// ``` +/// - +/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => +/// u.m(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. +/// ... +/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the +/// method declaration `D` be the implementation of `m` which is invoked by the +/// expression in the body. Let `T` be the class that contains D. +/// +/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is +/// the built-in class `Object`. +/// +/// @description Check that if `pj` is covariant then `Tj` is `Object?` at +/// run time. Test covariant-by-class parameters. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/expect.dart'; +import '../../../../Utils/static_type_helper.dart'; + +class C { + X m(X r1, Y r2, [X? p1]) { + return 42 as X; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType< + Exactly< + Object? Function(Object? r1, Y r2, [Object? p1]) + > + >(); + + Expect.isTrue( + f is Object? Function(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 new file mode 100644 index 0000000000..5cbcd52a78 --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_A03_t03.dart @@ -0,0 +1,49 @@ +// 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: +/// ... +/// ``` +/// - +/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => +/// u.m(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. +/// ... +/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the +/// method declaration `D` be the implementation of `m` which is invoked by the +/// expression in the body. Let `T` be the class that contains D. +/// +/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is +/// the built-in class `Object`. +/// +/// @description Check that if `pj` is covariant then `Tj` is `Object?` at +/// run time. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/expect.dart'; +import '../../../../Utils/static_type_helper.dart'; + +class C { + X m(covariant X r1, covariant Y r2, [covariant int? p1]) { + return 42 as X; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType< + Exactly(num r1, Y r2, [int? p1])> + >(); + + Expect.isTrue( + f is num Function(Object? r1, Object? r2, [Object? p1])); +} From 6069250bb353a64bef1e05e50aa2287c5ca0c815 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Wed, 29 Jan 2025 15:48:18 +0200 Subject: [PATCH 2/2] Implement review recommendations --- .../method_closurization_named_params_A03_t02.dart | 2 +- .../method_closurization_named_params_A03_t03.dart | 8 ++++---- .../method_closurization_positional_params_A03_t02.dart | 2 +- .../method_closurization_positional_params_A03_t03.dart | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) 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 a793c7d79a..e1d6bfa843 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 @@ -37,7 +37,7 @@ class C { } main() { - C o = C(); + C o = C(); final f = o.m; f.expectStaticType< Exactly(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 9a5fec6b41..45ff25cfcf 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 @@ -31,7 +31,7 @@ import '../../../../Utils/expect.dart'; import '../../../../Utils/static_type_helper.dart'; class C { - X m( + X m( covariant X r1, covariant Y r2, { required covariant int p1, @@ -41,14 +41,14 @@ class C { } main() { - C o = C(); + var o = C(); final f = o.m; f.expectStaticType< - Exactly(num r1, Y r2, {required int p1})> + Exactly(num r1, Y r2, {required int p1})> >(); Expect.isTrue( - f is num Function( + f is num Function( Object? r1, Object? r2, { required 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 fa0a606baf..f5671049e0 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 @@ -38,7 +38,7 @@ class C { } main() { - C o = C(); + C o = C(); final f = o.m; f.expectStaticType< Exactly< 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 5cbcd52a78..1dead7c2b7 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 @@ -32,18 +32,18 @@ import '../../../../Utils/expect.dart'; import '../../../../Utils/static_type_helper.dart'; class C { - X m(covariant X r1, covariant Y r2, [covariant int? p1]) { + X m(covariant X r1, covariant Y r2, [covariant int? p1]) { return 42 as X; } } main() { - C o = C(); + var o = C(); final f = o.m; f.expectStaticType< - Exactly(num r1, Y r2, [int? p1])> + Exactly(num r1, Y r2, [int? p1])> >(); Expect.isTrue( - f is num Function(Object? r1, Object? r2, [Object? p1])); + f is num Function(Object? r1, Object? r2, [Object? p1])); }