From bfa8484e0ad3d5423426d40789f4cceb1e3eb884 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Mon, 27 Jan 2025 15:38:05 +0200 Subject: [PATCH 1/4] #3054. Existing tests renamed to Instance Method Closurization --- ...method_closurization_named_params_t01.dart | 51 ++++++++++++++++ ...method_closurization_named_params_t02.dart | 58 +++++++++++++++++++ ...method_closurization_named_params_t03.dart | 38 ++++++++++++ ...method_closurization_named_params_t04.dart | 39 +++++++++++++ ...d_closurization_positional_params_t01.dart | 52 +++++++++++++++++ ...d_closurization_positional_params_t02.dart | 45 ++++++++++++++ ...d_closurization_positional_params_t03.dart | 39 +++++++++++++ ...d_closurization_positional_params_t04.dart | 40 +++++++++++++ ...method_closurization_named_params_t01.dart | 44 -------------- ...method_closurization_named_params_t02.dart | 51 ---------------- ...d_closurization_positional_params_t01.dart | 43 -------------- ...d_closurization_positional_params_t02.dart | 50 ---------------- 12 files changed, 362 insertions(+), 188 deletions(-) create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t01.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t02.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t01.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t02.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart create mode 100644 Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart delete mode 100644 Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_named_params_t01.dart delete mode 100644 Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_named_params_t02.dart delete mode 100644 Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_positional_params_t01.dart delete mode 100644 Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_positional_params_t02.dart diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t01.dart new file mode 100644 index 0000000000..2ea661eeff --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t01.dart @@ -0,0 +1,51 @@ +// Copyright (c) 2015, 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. +/// +/// @description Check that closurization of 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` is 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); +/// ``` +/// @author sgrekhov@unipro.ru + +import '../../../../Utils/expect.dart'; + +class C { + double m(int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) { + return r1 * r2 * r3 * p1 * p2 * (p3 ?? 1); + } +} + +main() { + C o = new C(); + var f = o.m; + + var f1 = (int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) { + return o.m(r1, r2, r3, p1: p1, p2: p2, p3: p3); + }; + + Expect.equals(f(1, 2, 3.0, p1: 4, p2: 5, p3: 6), f1(1, 2, 3.0, p1: 4, p2: 5, p3: 6)); + Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5)); + Expect.equals(f(-1, 3, 9.1, p1: 4, p3: null), f1(-1, 3, 9.1, p1: 4)); + Expect.equals(f(-1, 3, 9.1, p2: 4, p3: null), f1(-1, 3, 9.1, p2: 4)); + Expect.equals(f(-1, 3, 9.1, p3: 4), f1(-1, 3, 9.1, p3: 4)); +} diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t02.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t02.dart new file mode 100644 index 0000000000..39e159c0b2 --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t02.dart @@ -0,0 +1,58 @@ +// Copyright (c) 2015, 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. +/// +/// @description Check that closurization of 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` is 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); +/// ``` +/// Test the case when `m` calls another method. +/// @author sgrekhov@unipro.ru + +import '../../../../Utils/expect.dart'; + +class C { + double n(int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) { + return r1 * r2 * r3 * p1 * p2 * (p3 ?? 1); + } + + sum(a, b) => a + b; + + double m(int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) { + return sum(r3, p2) + n(r1, r2, r3, p1: p1, p2: p2, p3: p3); + } +} + +main() { + C o = new C(); + var f = o.m; + + var f1 = (int r1, int r2, double r3, {p1 = 2, p2 = -3, p3}) { + return o.m(r1, r2, r3, p1: p1, p2: p2, p3: p3); + }; + + Expect.equals(f(1, 2, 3.2, p1: 4, p2: 5, p3: 6), f1(1, 2, 3.2, p1: 4, p2: 5, p3: 6)); + Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5)); + Expect.equals(f(-1, 3, 9.1, p1: 4, p3: null), f1(-1, 3, 9.1, p1: 4)); + Expect.equals(f(-1, 3, 9.1, p2: 4, p3: null), f1(-1, 3, 9.1, p2: 4)); + Expect.equals(f(-1, 3, 9.1, p3: 4), f1(-1, 3, 9.1, p3: 4)); +} diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart new file mode 100644 index 0000000000..f70ddfb706 --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart @@ -0,0 +1,38 @@ +// 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. +/// ... +/// `B′ j, j ∈ 1..s`, are determined as follows: If `o` is an instance of a +/// non-generic class, `B′ j = Bj,j ∈ 1..s`. +/// +/// @description Check that if `o` is an instance of a non-generic class, then +/// `B′ j = Bj,j ∈ 1..s`. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/static_type_helper.dart'; + +class C { + X0 m(X1 r1, {required X2 p1}) { + return (r1 + p1) as X0; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType>(); +} diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart new file mode 100644 index 0000000000..8029cce00f --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart @@ -0,0 +1,39 @@ +// 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. +/// ... +/// Let `X′1,...,X′s`′ be the formal type parameters of the class of `o`, and +/// `t′1,...,t′s′` be the actual type arguments. Then +/// `B′ j = [t′ 1/X′ 1,...,t′ s′ /X′ s′ ]Bj, j ∈ 1..s`. +/// +/// @description Check that if `o` is an instance of a generic class, then +/// `B′ j = [t′ 1/X′ 1,...,t′ s′ /X′ s′ ]Bj, j ∈ 1..s`. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/static_type_helper.dart'; + +class C { + X0 m(X1 r1, {required X2 p1}) { + return (r1 + p1) as X0; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType>(); +} diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t01.dart new file mode 100644 index 0000000000..0ce2d07bbb --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t01.dart @@ -0,0 +1,52 @@ +// Copyright (c) 2015, 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. +/// +/// @description Check that closurization of 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` is equivalent to +/// ... +/// ``` +/// - +/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => +/// u.m(p1, ..., pn+k); +/// ``` +/// @author sgrekhov@unipro.ru + +import '../../../../Utils/expect.dart'; + +class C { + double m(int r1, int r2, double r3, [p1 = 2, p2 = -3, p3]) { + return r1 * r2 * r3 * p1 * p2 * (p3 ?? 1); + } +} + +main() { + C o = new C(); + var f = o.m; + + var f1 = (int r1, int r2, double r3, [p1 = 2, p2 = -3, p3]) { + return o.m(r1, r2, r3, p1, p2, p3); + }; + + Expect.equals(f(1, 2, 3.4, 4, 5, 6), f1(1, 2, 3.4, 4, 5, 6)); + Expect.equals(f(2, 3, 8.5, 2, -3, null), f1(2, 3, 8.5)); + Expect.equals(f(-1, 3, 9.1, 4), f1(-1, 3, 9.1, 4)); + Expect.equals(f(-1, 3, 9.1, 4, 5), f1(-1, 3, 9.1, 4, 5)); +} diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t02.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t02.dart new file mode 100644 index 0000000000..f9de2a2b75 --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t02.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2015, 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. + +/// @description Check that closurization of 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` is equivalent to +/// ... +/// ``` +/// - +/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => +/// u.m(p1, ..., pn+k); +/// ``` +/// Test the case when m calls another method. +/// +/// @author sgrekhov@unipro.ru + +import '../../../../Utils/expect.dart'; + +class C { + double n(int r1, int r2, double r3, p1, p2, p3) { + return r1 * r2 * r3 * p1 * p2 * (p3 ?? 1); + } + + int sum(a, b) => a + b; + + double m(int r1, int r2, double r3, [p1 = 2, p2 = -3, p3]) { + return sum(r1, p1) * n(r1, r2, r3, p1, p2, p3); + } +} + +main() { + C o = new C(); + var f = o.m; + + var f1 = (int r1, int r2, double r3, [p1 = 2, p2 = -3, p3]) { + return o.m(r1, r2, r3, p1, p2, p3); + }; + + Expect.equals(f(1, 2, 3.2, 4, 5, 6), f1(1, 2, 3.2, 4, 5, 6)); + Expect.equals(f(2, 3, 8.5, 2, -3, null), f1(2, 3, 8.5)); + Expect.equals(f(-1, 3, 9.1, 4), f1(-1, 3, 9.1, 4)); + Expect.equals(f(-1, 3, 9.1, 4, 5), f1(-1, 3, 9.1, 4, 5)); +} diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart new file mode 100644 index 0000000000..8da80568ff --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart @@ -0,0 +1,39 @@ +// 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. +/// ... +/// `B′ j, j ∈ 1..s`, are determined as follows: If `o` is an instance of a +/// non-generic class, `B′ j = Bj,j ∈ 1..s`. +/// +/// @description Check that if `o` is an instance of a non-generic class, then +/// `B′ j = Bj,j ∈ 1..s`. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/static_type_helper.dart'; + +class C { + X0 m(X1 r1, [X2? p1]) { + return (r1 + p1!) as X0; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType>(); +} diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart new file mode 100644 index 0000000000..2b40bb29ab --- /dev/null +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart @@ -0,0 +1,40 @@ +// 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. +/// ... +/// Let `X′1,...,X′s`′ be the formal type parameters of the class of `o`, and +/// `t′1,...,t′s′` be the actual type arguments. Then +/// `B′ j = [t′ 1/X′ 1,...,t′ s′ /X′ s′ ]Bj, j ∈ 1..s`. +/// +/// @description Check that if `o` is an instance of a generic class, then +/// `B′ j = [t′ 1/X′ 1,...,t′ s′ /X′ s′ ]Bj, j ∈ 1..s`. +/// @author sgrekhov22@gmail.com + +import '../../../../Utils/static_type_helper.dart'; + +class C { + X0 m(X1 r1, [X2? p1]) { + return (r1 + p1!) as X0; + } +} + +main() { + C o = C(); + final f = o.m; + f.expectStaticType>(); +} diff --git a/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_named_params_t01.dart b/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_named_params_t01.dart deleted file mode 100644 index 11b070b69e..0000000000 --- a/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_named_params_t01.dart +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2015, 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: -/// ... -/// • (r1, . . . , rn , {p1 : d1, . . . , pk : dk }) { -/// return u.m(r1, . . . , rn, p1 : p1, . . . , pk : pk ); -/// } -/// if f is named m and has required parameters r1, . . . , rn , and named -/// parameters p1 , . . . , pk with defaults d1, . . . , dk. -/// -/// @description Check that closurization of method -/// m(r1, . . . , rn, p1 : p1, . . . , pk : pk ) on object o is -/// equivalent to (r1, . . . , rn , {p1 : d1, . . . , pk : dk }) { -/// return u.m(r1, . . . , rn, p1 : p1, . . . , pk : pk ); -/// } -/// -/// @author sgrekhov@unipro.ru - -import '../../../../Utils/expect.dart'; - -class C { - double m(int r1, int r2, double r3, {p1 = 2, p2 = -3, p3 = -7}) { - return r1 * r2 * r3 * p1 * p2 * p3; - } -} - -main() { - C o = new C(); - var f = o.m; - - var f1 = (int r1, int r2, double r3, {p1 = 2, p2 = -3, p3 = -7}) { - return o.m(r1, r2, r3, p1: p1, p2: p2, p3: p3); - }; - - Expect.equals(f(1, 2, 3.0, p1: 4, p2: 5, p3: 6), f1(1, 2, 3.0, p1: 4, p2: 5, p3: 6)); - Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5)); - Expect.equals(f(-1, 3, 9.1, p1: 4), f1(-1, 3, 9.1, p1: 4)); - Expect.equals(f(-1, 3, 9.1, p2: 4), f1(-1, 3, 9.1, p2: 4)); - Expect.equals(f(-1, 3, 9.1, p3: 4), f1(-1, 3, 9.1, p3: 4)); -} diff --git a/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_named_params_t02.dart b/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_named_params_t02.dart deleted file mode 100644 index 69b355e068..0000000000 --- a/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_named_params_t02.dart +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2015, 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: -/// ... -/// • (r1, . . . , rn , {p1 : d1, . . . , pk : dk }) { -/// return u.m(r1, . . . , rn, p1 : p1, . . . , pk : pk ); -/// } -/// if f is named m and has required parameters r1, . . . , rn , and named -/// parameters p1 , . . . , pk with defaults d1, . . . , dk. -/// -/// @description Check that closurization of method -/// m(r1, . . . , rn, p1 : p1, . . . , pk : pk ) on object o is -/// equivalent to (r1, . . . , rn , {p1 : d1, . . . , pk : dk }) { -/// return u.m(r1, . . . , rn, p1 : p1, . . . , pk : pk ); -/// } -/// Test the case when m calls another method -/// -/// @author sgrekhov@unipro.ru - -import '../../../../Utils/expect.dart'; - -class C { - double n(int r1, int r2, double r3, {p1 = 2, p2 = -3, p3 = -7}) { - return r1 * r2 * r3 * p1 * p2 * p3; - } - - sum(a, b) => a + b; - - double m(int r1, int r2, double r3, {p1 = 2, p2 = -3, p3 = -7}) { - return sum(r3, p2) + n(r1, r2, r3, p1: p1, p2: p2, p3: p3); - } -} - -main() { - C o = new C(); - var f = o.m; - - var f1 = (int r1, int r2, double r3, {p1 = 2, p2 = -3, p3 = -7}) { - return o.m(r1, r2, r3, p1: p1, p2: p2, p3: p3); - }; - - Expect.equals(f(1, 2, 3.2, p1: 4, p2: 5, p3: 6), f1(1, 2, 3.2, p1: 4, p2: 5, p3: 6)); - Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5)); - Expect.equals(f(-1, 3, 9.1, p1: 4), f1(-1, 3, 9.1, p1: 4)); - Expect.equals(f(-1, 3, 9.1, p2: 4), f1(-1, 3, 9.1, p2: 4)); - Expect.equals(f(-1, 3, 9.1, p3: 4), f1(-1, 3, 9.1, p3: 4)); -} diff --git a/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_positional_params_t01.dart b/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_positional_params_t01.dart deleted file mode 100644 index e9ce32f6a7..0000000000 --- a/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_positional_params_t01.dart +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2015, 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: -/// ... -/// • (r1, . . . , rn , [p1 = d1, . . . , pk = dk]) { -/// return u.m(r1, . . . , rn , p1, . . . , pk ); -/// } -/// if f is named m and has required parameters r 1 , . . . , r n , and optional -/// positional parameters p1, . . . , pk with defaults d1, . . . , dk. -/// -/// @description Check that closurization of method -/// m(r1, . . . , rn , [p1 = d1, . . . , pk = dk]) on object o is -/// equivalent to (r1, . . . , rn , [p1 = d1, . . . , pk = dk]) { -/// return u.m(r1, . . . , rn , p1, . . . , pk ); -/// } -/// -/// @author sgrekhov@unipro.ru - -import '../../../../Utils/expect.dart'; - -class C { - double m(int r1, int r2, double r3, [p1 = 2, p2 = -3, p3 = -7]) { - return r1 * r2 * r3 * p1 * p2 * p3; - } -} - -main() { - C o = new C(); - var f = o.m; - - var f1 = (int r1, int r2, double r3, [p1 = 2, p2 = -3, p3 = -7]) { - return o.m(r1, r2, r3, p1, p2, p3); - }; - - Expect.equals(f(1, 2, 3.4, 4, 5, 6), f1(1, 2, 3.4, 4, 5, 6)); - Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5)); - Expect.equals(f(-1, 3, 9.1, 4), f1(-1, 3, 9.1, 4)); - Expect.equals(f(-1, 3, 9.1, 4, 5), f1(-1, 3, 9.1, 4, 5)); -} diff --git a/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_positional_params_t02.dart b/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_positional_params_t02.dart deleted file mode 100644 index 06226fb5f4..0000000000 --- a/Language/Expressions/Property_Extraction/Ordinary_Member_Closurization/method_closurization_positional_params_t02.dart +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2015, 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: -/// ... -/// • (r1, . . . , rn , [p1 = d1, . . . , pk = dk]) { -/// return u.m(r1, . . . , rn , p1, . . . , pk ); -/// } -/// if f is named m and has required parameters r 1 , . . . , r n , and optional -/// positional parameters p1, . . . , pk with defaults d1, . . . , dk. -/// -/// @description Check that closurization of method -/// m(r1, . . . , rn , [p1 = d1, . . . , pk = dk]) on object o is -/// equivalent to (r1, . . . , rn , [p1 = d1, . . . , pk = dk]) { -/// return u.m(r1, . . . , rn , p1, . . . , pk ); -/// } -/// Test the case when m calls another method -/// -/// @author sgrekhov@unipro.ru - -import '../../../../Utils/expect.dart'; - -class C { - double n(int r1, int r2, double r3, p1, p2, p3) { - return r1 * r2 * r3 * p1 * p2 * p3; - } - - int sum(a, b) => a + b; - - double m(int r1, int r2, double r3, [p1 = 2, p2 = -3, p3 = -7]) { - return sum(r1, p1) * n(r1, r2, r3, p1, p2, p3); - } -} - -main() { - C o = new C(); - var f = o.m; - - var f1 = (int r1, int r2, double r3, [p1 = 2, p2 = -3, p3 = -7]) { - return o.m(r1, r2, r3, p1, p2, p3); - }; - - Expect.equals(f(1, 2, 3.2, 4, 5, 6), f1(1, 2, 3.2, 4, 5, 6)); - Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5)); - Expect.equals(f(-1, 3, 9.1, 4), f1(-1, 3, 9.1, 4)); - Expect.equals(f(-1, 3, 9.1, 4, 5), f1(-1, 3, 9.1, 4, 5)); -} From 0b54754b86a94a708e30c7e7b7e7386c90293ec5 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Mon, 27 Jan 2025 17:50:20 +0200 Subject: [PATCH 2/4] Update tests to follow the assertion --- .../method_closurization_named_params_t03.dart | 11 ++++++++--- .../method_closurization_named_params_t04.dart | 12 ++++++++---- .../method_closurization_positional_params_t03.dart | 9 ++++++--- .../method_closurization_positional_params_t04.dart | 10 ++++++---- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart index f70ddfb706..033ac32d77 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart @@ -23,10 +23,11 @@ /// `B′ j = Bj,j ∈ 1..s`. /// @author sgrekhov22@gmail.com +import '../../../../Utils/expect.dart'; import '../../../../Utils/static_type_helper.dart'; -class C { - X0 m(X1 r1, {required X2 p1}) { +class C { + X0 m(X1 r1, {required X2 p1}) { return (r1 + p1) as X0; } } @@ -34,5 +35,9 @@ class C { main() { C o = C(); final f = o.m; - f.expectStaticType>(); + f.expectStaticType< + Exactly( + X1 r1, {required X2 p1})>>(); + Expect.equals(o.m(1, p1: 2), f(1, p1: 2)); + Expect.equals(o.m(1, p1: 3), f(1, p1: 3)); } diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart index 8029cce00f..94a10befbd 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart @@ -24,16 +24,20 @@ /// `B′ j = [t′ 1/X′ 1,...,t′ s′ /X′ s′ ]Bj, j ∈ 1..s`. /// @author sgrekhov22@gmail.com +import '../../../../Utils/expect.dart'; import '../../../../Utils/static_type_helper.dart'; -class C { - X0 m(X1 r1, {required X2 p1}) { +class C { + X0 m(X1 r1, {required X2 p1}) { return (r1 + p1) as X0; } } main() { - C o = C(); + C o = C(); final f = o.m; - f.expectStaticType>(); + f.expectStaticType< + Exactly( + X1 r1, {required X2 p1})>>(); + Expect.equals(o.m(1, p1: 2), f(1, p1: 2)); } diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart index 8da80568ff..2842359c0e 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart @@ -24,10 +24,11 @@ /// `B′ j = Bj,j ∈ 1..s`. /// @author sgrekhov22@gmail.com +import '../../../../Utils/expect.dart'; import '../../../../Utils/static_type_helper.dart'; -class C { - X0 m(X1 r1, [X2? p1]) { +class C { + X0 m(X1 r1, [X2? p1]) { return (r1 + p1!) as X0; } } @@ -35,5 +36,7 @@ class C { main() { C o = C(); final f = o.m; - f.expectStaticType>(); + f.expectStaticType(X1 r1, [X2? p1])>>(); + Expect.equals(o.m(1, 2), f(1, 2)); + Expect.equals(o.m(1, 3), f(1, 3)); } diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart index 2b40bb29ab..c821f66c5b 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart @@ -25,16 +25,18 @@ /// `B′ j = [t′ 1/X′ 1,...,t′ s′ /X′ s′ ]Bj, j ∈ 1..s`. /// @author sgrekhov22@gmail.com +import '../../../../Utils/expect.dart'; import '../../../../Utils/static_type_helper.dart'; -class C { - X0 m(X1 r1, [X2? p1]) { +class C { + X0 m(X1 r1, [X2? p1]) { return (r1 + p1!) as X0; } } main() { - C o = C(); + C o = C(); final f = o.m; - f.expectStaticType>(); + f.expectStaticType(X1 r1, [X2? p1])>>(); + Expect.equals(o.m(1, 2), f(1, 2)); } From a49944b27c5ae2bb4b418db56f71d106877b3504 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Tue, 28 Jan 2025 10:55:59 +0200 Subject: [PATCH 3/4] Add dynamic type test --- .../method_closurization_named_params_t03.dart | 15 +++++++++++++-- .../method_closurization_named_params_t04.dart | 15 +++++++++++++-- ...ethod_closurization_positional_params_t03.dart | 15 ++++++++++++++- ...ethod_closurization_positional_params_t04.dart | 15 ++++++++++++++- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart index 033ac32d77..badebee1d6 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t03.dart @@ -36,8 +36,19 @@ main() { C o = C(); final f = o.m; f.expectStaticType< - Exactly( - X1 r1, {required X2 p1})>>(); + Exactly< + X0 Function( + X1 r1, { + required X2 p1, + }) + > + >(); + Expect.isTrue( + f is X0 Function( // ignore: unnecessary_type_check + X1 r1, { + required X2 p1, + }), + ); Expect.equals(o.m(1, p1: 2), f(1, p1: 2)); Expect.equals(o.m(1, p1: 3), f(1, p1: 3)); } diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart index 94a10befbd..7c76281339 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t04.dart @@ -37,7 +37,18 @@ main() { C o = C(); final f = o.m; f.expectStaticType< - Exactly( - X1 r1, {required X2 p1})>>(); + Exactly< + X0 Function( + X1 r1, { + required X2 p1, + }) + > + >(); + Expect.isTrue( + f is X0 Function( // ignore: unnecessary_type_check + X1 r1, { + required X2 p1, + }), + ); Expect.equals(o.m(1, p1: 2), f(1, p1: 2)); } diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart index 2842359c0e..0468f789c0 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t03.dart @@ -36,7 +36,20 @@ class C { main() { C o = C(); final f = o.m; - f.expectStaticType(X1 r1, [X2? p1])>>(); + f.expectStaticType< + Exactly< + X0 Function( + X1 r1, [ + X2? p1, + ]) + > + >(); + Expect.isTrue( + f is X0 Function( // ignore: unnecessary_type_check + X1 r1, [ + X2? p1, + ]), + ); Expect.equals(o.m(1, 2), f(1, 2)); Expect.equals(o.m(1, 3), f(1, 3)); } diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart index c821f66c5b..01757f04e3 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t04.dart @@ -37,6 +37,19 @@ class C { main() { C o = C(); final f = o.m; - f.expectStaticType(X1 r1, [X2? p1])>>(); + f.expectStaticType< + Exactly< + X0 Function( + X1 r1, [ + X2? p1, + ]) + > + >(); + Expect.isTrue( + f is X0 Function( // ignore: unnecessary_type_check + X1 r1, [ + X2? p1, + ]), + ); Expect.equals(o.m(1, 2), f(1, 2)); } From 714436687595958677ed3c7539000791c84f21b8 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Tue, 28 Jan 2025 17:37:49 +0200 Subject: [PATCH 4/4] Update descriptions --- .../method_closurization_named_params_t01.dart | 6 +++++- .../method_closurization_named_params_t02.dart | 7 +++++-- .../method_closurization_positional_params_t01.dart | 1 + .../method_closurization_positional_params_t02.dart | 3 +-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t01.dart index 2ea661eeff..b777479959 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t01.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t01.dart @@ -25,6 +25,7 @@ /// (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); /// ``` +/// Test a non-generic case. /// @author sgrekhov@unipro.ru import '../../../../Utils/expect.dart'; @@ -43,7 +44,10 @@ main() { return o.m(r1, r2, r3, p1: p1, p2: p2, p3: p3); }; - Expect.equals(f(1, 2, 3.0, p1: 4, p2: 5, p3: 6), f1(1, 2, 3.0, p1: 4, p2: 5, p3: 6)); + Expect.equals( + f(1, 2, 3.0, p1: 4, p2: 5, p3: 6), + f1(1, 2, 3.0, p1: 4, p2: 5, p3: 6), + ); Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5)); Expect.equals(f(-1, 3, 9.1, p1: 4, p3: null), f1(-1, 3, 9.1, p1: 4)); Expect.equals(f(-1, 3, 9.1, p2: 4, p3: null), f1(-1, 3, 9.1, p2: 4)); diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t02.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t02.dart index 39e159c0b2..849ddbdca3 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t02.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_named_params_t02.dart @@ -25,7 +25,7 @@ /// (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); /// ``` -/// Test the case when `m` calls another method. +/// Test a non-generic case when `m` calls another method. /// @author sgrekhov@unipro.ru import '../../../../Utils/expect.dart'; @@ -50,7 +50,10 @@ main() { return o.m(r1, r2, r3, p1: p1, p2: p2, p3: p3); }; - Expect.equals(f(1, 2, 3.2, p1: 4, p2: 5, p3: 6), f1(1, 2, 3.2, p1: 4, p2: 5, p3: 6)); + Expect.equals( + f(1, 2, 3.2, p1: 4, p2: 5, p3: 6), + f1(1, 2, 3.2, p1: 4, p2: 5, p3: 6), + ); Expect.equals(f(2, 3, 8.5), f1(2, 3, 8.5)); Expect.equals(f(-1, 3, 9.1, p1: 4, p3: null), f1(-1, 3, 9.1, p1: 4)); Expect.equals(f(-1, 3, 9.1, p2: 4, p3: null), f1(-1, 3, 9.1, p2: 4)); diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t01.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t01.dart index 0ce2d07bbb..cefc4dace0 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t01.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t01.dart @@ -27,6 +27,7 @@ /// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => /// u.m(p1, ..., pn+k); /// ``` +/// Test a non-generic case. /// @author sgrekhov@unipro.ru import '../../../../Utils/expect.dart'; diff --git a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t02.dart b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t02.dart index f9de2a2b75..dd977bac2f 100644 --- a/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t02.dart +++ b/Language/Expressions/Property_Extraction/Instance_Method_Closurization/method_closurization_positional_params_t02.dart @@ -12,8 +12,7 @@ /// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => /// u.m(p1, ..., pn+k); /// ``` -/// Test the case when m calls another method. -/// +/// Test a non-generic case when `m` calls another method. /// @author sgrekhov@unipro.ru import '../../../../Utils/expect.dart';