From 9b05eab312a0247b890c06a05ef667e56a4534ff Mon Sep 17 00:00:00 2001 From: "Sergey G. Grekhov" Date: Wed, 29 Jan 2025 16:38:46 +0200 Subject: [PATCH] #3054. Add covariant parameters tests (#3059) 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..e1d6bfa843 --- /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..45ff25cfcf --- /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() { + var 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..f5671049e0 --- /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..1dead7c2b7 --- /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() { + var 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])); +}