-
Notifications
You must be signed in to change notification settings - Fork 29
#3057. Add some promotion tests for extension types #3183
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
46 changes: 46 additions & 0 deletions
46
TypeSystem/flow-analysis/promotion_via_assignment_A07_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,46 @@ | ||
| // 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 We say that a variable `x` is promotable via assignment of an | ||
| /// expression of type `T` given variable model `VM` if | ||
| /// - `VM = VariableModel(declared, promoted, tested, assigned, unassigned, | ||
| /// captured)` | ||
| /// - and captured is false | ||
| /// - and `S` is the current type of `x` in `VM` | ||
| /// - and `T <: S` and not `S <: T` | ||
| /// - and `T` is a type of interest for `x` in `tested` | ||
| /// | ||
| /// @description Checks that a variable is not promotable if `T` is not a | ||
| /// subtype of `S`. Test extension types. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| extension type ET1(int v) {} | ||
| extension type ET2(int v) implements Object {} | ||
| extension type ET3(int v) implements int {} | ||
|
|
||
| test1(Object? o) { | ||
| if (o is ET1) {} | ||
| o = 42; | ||
| o.expectStaticType<Exactly<Object>>(); | ||
| } | ||
|
|
||
| test2(Object? o) { | ||
| if (o is ET2) {} | ||
| o = 42; | ||
| o.expectStaticType<Exactly<Object>>(); | ||
| } | ||
|
|
||
| test3(Object? o) { | ||
| if (o is ET3) {} | ||
| o = 42; | ||
| o.expectStaticType<Exactly<Object>>(); | ||
| } | ||
|
|
||
| main() { | ||
| test1(1); | ||
| test2(2); | ||
| test3(3); | ||
| } |
46 changes: 46 additions & 0 deletions
46
TypeSystem/flow-analysis/promotion_via_assignment_A07_t02.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,46 @@ | ||
| // 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 We say that a variable `x` is promotable via assignment of an | ||
| /// expression of type `T` given variable model `VM` if | ||
| /// - `VM = VariableModel(declared, promoted, tested, assigned, unassigned, | ||
| /// captured)` | ||
| /// - and captured is false | ||
| /// - and `S` is the current type of `x` in `VM` | ||
| /// - and `T <: S` and not `S <: T` | ||
| /// - and `T` is a type of interest for `x` in `tested` | ||
| /// | ||
| /// @description Checks that a variable is not promotable if `T` is not a | ||
| /// subtype of `S`. Test extension types. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| extension type ET1(int v) {} | ||
| extension type ET2(int v) implements Object {} | ||
| extension type ET3(int v) implements int {} | ||
|
|
||
| test1(num o) { | ||
| if (o is ET1) {} | ||
| o = 42; | ||
| o.expectStaticType<Exactly<num>>(); | ||
| } | ||
|
|
||
| test2(num o) { | ||
| if (o is ET2) {} | ||
| o = 42; | ||
| o.expectStaticType<Exactly<num>>(); | ||
| } | ||
|
|
||
| test3(num o) { | ||
| if (o is ET3) {} | ||
| o = 42; | ||
| o.expectStaticType<Exactly<num>>(); | ||
| } | ||
|
|
||
| main() { | ||
| test1(1); | ||
| test2(2); | ||
| test3(3); | ||
| } |
47 changes: 47 additions & 0 deletions
47
TypeSystem/flow-analysis/promotion_via_type_test_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,47 @@ | ||
| // 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 We say that a variable `x` is promotable via type test with type | ||
| /// `T` given variable model `VM` if | ||
| /// - `VM = VariableModel(declared, promoted, tested, assigned, unassigned, | ||
| /// captured)` | ||
| /// - and `captured` is `false` | ||
| /// - and `S` is the current type of `x` in `VM` | ||
| /// - and not `S <: T` | ||
| /// - and `T <: S` or (`S` is `X extends R` and `T <: R`) or (`S` is `X & R` and | ||
| /// `T <: R`) | ||
| /// | ||
| /// @description Checks that a variable is not promotable if `T` is not a | ||
| /// subtype of `S`. Test extension types. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| extension type ET1(num v) {} | ||
| extension type ET2(num v) implements Object {} | ||
| extension type ET3(num v) implements num {} | ||
|
|
||
| test1(ET1 et) { | ||
| if (et is int) { | ||
| et.expectStaticType<Exactly<ET1>>(); | ||
| } | ||
| } | ||
|
|
||
| test2(ET2 et) { | ||
| if (et is int) { | ||
| et.expectStaticType<Exactly<ET2>>(); | ||
| } | ||
| } | ||
|
|
||
| test3(ET3 et) { | ||
| if (et is int) { | ||
| et.expectStaticType<Exactly<ET3>>(); | ||
| } | ||
| } | ||
|
|
||
| main() { | ||
| test1(ET1(0)); | ||
| test2(ET2(0)); | ||
| test3(ET3(0)); | ||
| } |
50 changes: 50 additions & 0 deletions
50
TypeSystem/flow-analysis/promotion_via_type_test_A05_t02.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,50 @@ | ||
| // 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 We say that a variable `x` is promotable via type test with type | ||
| /// `T` given variable model `VM` if | ||
| /// - `VM = VariableModel(declared, promoted, tested, assigned, unassigned, | ||
| /// captured)` | ||
| /// - and `captured` is `false` | ||
| /// - and `S` is the current type of `x` in `VM` | ||
| /// - and not `S <: T` | ||
| /// - and `T <: S` or (`S` is `X extends R` and `T <: R`) or (`S` is `X & R` and | ||
| /// `T <: R`) | ||
| /// | ||
| /// @description Checks that a variable is not promotable if `T` is not a | ||
| /// subtype of `S`. Test extension types. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| extension type ET1(int v) {} | ||
| extension type ET2(int v) implements Object {} | ||
| extension type ET3(int v) implements int {} | ||
|
|
||
| test1() { | ||
| num n = 42; | ||
| if (n is ET1) { | ||
| n.expectStaticType<Exactly<num>>(); | ||
| } | ||
| } | ||
|
|
||
| test2() { | ||
| num n = 42; | ||
| if (n is ET2) { | ||
| n.expectStaticType<Exactly<num>>(); | ||
| } | ||
| } | ||
|
|
||
| test3() { | ||
| num n = 42; | ||
| if (n is ET3) { | ||
| n.expectStaticType<Exactly<ET3>>(); // Promotable in this case | ||
| } | ||
| } | ||
|
|
||
| main() { | ||
| test1(); | ||
| test2(); | ||
| test3(); | ||
| } | ||
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.