-
Notifications
You must be signed in to change notification settings - Fork 29
#3054. Add more method clozurization tests #3060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...y_Extraction/Instance_Method_Closurization/method_closurization_named_params_A04_t01.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // 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. | ||
| /// ... | ||
| /// 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. | ||
| /// ... | ||
| /// If `T` is a non-generic class then for `j ∈ 1..n+k, Tj` is a type | ||
| /// annotation that denotes the same type as that which is denoted by the type | ||
| /// annotation on the corresponding parameter declaration in `D`. If that | ||
| /// parameter declaration has no type annotation then `Tj` is `dynamic`. | ||
| /// | ||
| /// @description Check that if `T` is a non-generic class then for | ||
| /// `j ∈ 1..n+k, Tj` is a type annotation that denotes the same type as that | ||
| /// which is denoted by the type annotation on the corresponding parameter | ||
| /// declaration in `D` or `dynamic` if the parameter declaration has no type | ||
| /// annotation. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../../../Utils/expect.dart'; | ||
| import '../../../../Utils/static_type_helper.dart'; | ||
|
|
||
| class C { | ||
| 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< | ||
| Exactly< | ||
| Y Function<X, Y extends num>( | ||
| String r1, | ||
| Y r2, | ||
| dynamic r3, { | ||
| X? p1, | ||
| int p2, | ||
| dynamic p3, | ||
| }) | ||
| > | ||
| >(); | ||
|
|
||
| Expect.isTrue( | ||
| f is Y Function<X, Y extends num>( // ignore: unnecessary_type_check | ||
| String r1, | ||
| Y r2, | ||
| dynamic r3, { | ||
| X? p1, | ||
| int p2, | ||
| dynamic p3, | ||
| }) | ||
| ); | ||
| } | ||
79 changes: 79 additions & 0 deletions
79
...y_Extraction/Instance_Method_Closurization/method_closurization_named_params_A05_t01.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // 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. | ||
| /// ... | ||
| /// 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. | ||
| /// ... | ||
| /// Otherwise `T` is a generic instantiation of a generic class `G`. Let | ||
| /// `X′′1,...,X′′s′′` be the formal type parameters of `G`, and | ||
| /// `t′′1,...,t′′s′′` be the actual type arguments of `o` at `T`. Then `Tj` is | ||
| /// a type annotation that denotes `[t′′ 1/X′′ 1,...,t′′ s′′ /X′′ s′′]Sj`, | ||
| /// where `Sj` is the type annotation of the corresponding parameter in `D`. If | ||
| /// that parameter declaration has no type annotation then `Tj` is `dynamic`. | ||
| /// | ||
| /// @description Check that if `T` is a generic instantiation of a generic class | ||
| /// `G` then `Tj` is a type annotation that denotes | ||
| /// `[t′′ 1/X′′ 1,...,t′′ s′′ /X′′ s′′]Sj`, where `Sj` is the type annotation of | ||
| /// the corresponding parameter in `D`. If that parameter declaration has no | ||
| /// type annotation then `Tj` is `dynamic`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../../../Utils/expect.dart'; | ||
| import '../../../../Utils/static_type_helper.dart'; | ||
|
|
||
| class C<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>[]; | ||
| } | ||
| } | ||
|
|
||
| main() { | ||
| var o = C<String>(); | ||
| final f = o.m; | ||
| f.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( | ||
| f 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, | ||
| }) | ||
| ); | ||
| } |
48 changes: 48 additions & 0 deletions
48
...y_Extraction/Instance_Method_Closurization/method_closurization_named_params_A06_t01.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // 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 `true` if and only if | ||
| /// `o1` and `o2` is the same object. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../../../Utils/expect.dart'; | ||
|
|
||
| class C { | ||
| 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; | ||
|
|
||
| Expect.equals(f1, f2); | ||
| Expect.notEquals(f1, f3); | ||
| } |
71 changes: 71 additions & 0 deletions
71
...raction/Instance_Method_Closurization/method_closurization_positional_params_A04_t01.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // 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. | ||
| /// ... | ||
| /// 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. | ||
| /// ... | ||
| /// If `T` is a non-generic class then for `j ∈ 1..n+k, Tj` is a type | ||
| /// annotation that denotes the same type as that which is denoted by the type | ||
| /// annotation on the corresponding parameter declaration in `D`. If that | ||
| /// parameter declaration has no type annotation then `Tj` is `dynamic`. | ||
| /// | ||
| /// @description Check that if `T` is a non-generic class then for | ||
| /// `j ∈ 1..n+k, Tj` is a type annotation that denotes the same type as that | ||
| /// which is denoted by the type annotation on the corresponding parameter | ||
| /// declaration in `D` or `dynamic` if the parameter declaration has no type | ||
| /// annotation. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../../../Utils/expect.dart'; | ||
| import '../../../../Utils/static_type_helper.dart'; | ||
|
|
||
| class C { | ||
| 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< | ||
| Exactly< | ||
| Y Function<X, Y extends num>( | ||
| String r1, | ||
| Y r2, | ||
| dynamic r3, [ | ||
| X? p1, | ||
| int p2, | ||
| dynamic p3, | ||
| ]) | ||
| > | ||
| >(); | ||
|
|
||
| Expect.isTrue( | ||
| f is Y Function<X, Y extends num>( // ignore: unnecessary_type_check | ||
| String r1, | ||
| Y r2, | ||
| dynamic r3, [ | ||
| X? p1, | ||
| int p2, | ||
| dynamic p3, | ||
| ]) | ||
| ); | ||
| } |
80 changes: 80 additions & 0 deletions
80
...raction/Instance_Method_Closurization/method_closurization_positional_params_A05_t01.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // 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. | ||
| /// ... | ||
| /// 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. | ||
| /// ... | ||
| /// Otherwise `T` is a generic instantiation of a generic class `G`. Let | ||
| /// `X′′1,...,X′′s′′` be the formal type parameters of `G`, and | ||
| /// `t′′1,...,t′′s′′` be the actual type arguments of `o` at `T`. Then `Tj` is | ||
| /// a type annotation that denotes `[t′′ 1/X′′ 1,...,t′′ s′′ /X′′ s′′]Sj`, | ||
| /// where `Sj` is the type annotation of the corresponding parameter in `D`. If | ||
| /// that parameter declaration has no type annotation then `Tj` is `dynamic`. | ||
| /// | ||
| /// @description Check that if `T` is a generic instantiation of a generic class | ||
| /// `G` then `Tj` is a type annotation that denotes | ||
| /// `[t′′ 1/X′′ 1,...,t′′ s′′ /X′′ s′′]Sj`, where `Sj` is the type annotation of | ||
| /// the corresponding parameter in `D`. If that parameter declaration has no | ||
| /// type annotation then `Tj` is `dynamic`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../../../Utils/expect.dart'; | ||
| import '../../../../Utils/static_type_helper.dart'; | ||
|
|
||
| class C<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>[]; | ||
| } | ||
| } | ||
|
|
||
| main() { | ||
| var o = C<String>(); | ||
| final f = o.m; | ||
| f.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( | ||
| f 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, | ||
| ]) | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.