-
Notifications
You must be signed in to change notification settings - Fork 29
#3057. Update instance check tests and add negated instance check ones #3131
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
12 commits
Select commit
Hold shift + click to select a range
4543565
#3057. Update instance check tests according to the spec chenges
sgrekhov 45fc5ec
Add `is!` tests
sgrekhov 3278f2e
Update assertion text
sgrekhov 75540bf
Apply review suggestions.
sgrekhov be59004
Update reachability_A12_t05.dart
eernstg 08d3a90
Update reachability_A12_t06.dart
eernstg a5ec955
Update reachability_A23_t05.dart
eernstg 279deaa
Update reachability_A23_t06.dart
eernstg f97eaa3
Update reachability_A23_t01.dart
eernstg 547bc45
Update reachability_A23_t02.dart
eernstg 16c1295
Update reachability_A23_t04.dart
eernstg b3c80ec
Update reachability_A23_t03.dart
eernstg 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
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
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
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
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
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,32 @@ | ||
| // 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 instance check If `N` is an expression of the form `E1 is S` | ||
| /// where the static type of `E1` is `T` then: | ||
| /// - Let `before(E1) = before(N)` | ||
| /// - If `T` is a bottom type, then: | ||
| /// - Let `true(N) = unreachable(after(E1))`. | ||
| /// - Let `false(N) = after(E1)`. | ||
| /// - Otherwise: | ||
| /// - Let `true(N) = promote(E1, S, after(E1))` | ||
| /// - Let `false(N) = promote(E1, factor(T, S), after(E1))` | ||
| /// | ||
| /// @description Checks that if `T` is a bottom type then | ||
| /// `true(N) = unreachable(after(E1))`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| test(x) { | ||
| late int i; | ||
| if (x is Never) { | ||
| i = 42; | ||
| } | ||
| i; // Definitely unassigned. | ||
| //^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| main() { | ||
| print(test); | ||
| } |
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,29 @@ | ||
| // 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 instance check If `N` is an expression of the form `E1 is S` | ||
| /// where the static type of `E1` is `T` then: | ||
| /// - Let `before(E1) = before(N)` | ||
| /// - If `T` is a bottom type, then: | ||
| /// - Let `true(N) = unreachable(after(E1))`. | ||
| /// - Let `false(N) = after(E1)`. | ||
| /// - Otherwise: | ||
| /// - Let `true(N) = promote(E1, S, after(E1))` | ||
| /// - Let `false(N) = promote(E1, factor(T, S), after(E1))` | ||
| /// | ||
| /// @description Checks that if `T` is a bottom type then `false(N) = after(E1)`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| test(x) { | ||
| int i; | ||
| if (x is Never) { | ||
| } else { | ||
| i = 42; | ||
| } | ||
| i; // Definitely assigned. | ||
| } | ||
|
|
||
| main() { | ||
| test(null); | ||
| } |
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,30 @@ | ||
| // 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 negated instance check If `N` is an expression of the form | ||
| /// `E1 is! S` where the static type of `E1` is `T` then: | ||
| /// - Let `before(E1) = before(N)` | ||
| /// - If `T` is a bottom type, then: | ||
| /// - Let `true(N) = after(E1)`. | ||
| /// - Let `false(N) = unreachable(after(E1))`. | ||
| /// - Otherwise: | ||
| /// - Let `true(N) = promote(E1, factor(T, S), after(E1))` | ||
| /// - Let `false(N) = promote(E1, S, after(E1))` | ||
| /// | ||
| /// @description Checks that for expression of the form `E1 is! S`, | ||
| /// `true(N) = promote(E1, factor(T, S), after(E1))` and | ||
| /// `false(N) = promote(E1, S, after(E1))`. Test `factor(T, S)` for the case | ||
| /// `T` is `R?` and `Null <: S`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| main() { | ||
| int? i = 2 > 1 ? null : 42; | ||
| if (i is! Null) { | ||
| i.expectStaticType<Exactly<int>>(); | ||
| } else { | ||
| Null n = i; | ||
| } | ||
| } | ||
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,30 @@ | ||
| // 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 negated instance check If `N` is an expression of the form | ||
| /// `E1 is! S` where the static type of `E1` is `T` then: | ||
| /// - Let `before(E1) = before(N)` | ||
| /// - If `T` is a bottom type, then: | ||
| /// - Let `true(N) = after(E1)`. | ||
| /// - Let `false(N) = unreachable(after(E1))`. | ||
| /// - Otherwise: | ||
| /// - Let `true(N) = promote(E1, factor(T, S), after(E1))` | ||
| /// - Let `false(N) = promote(E1, S, after(E1))` | ||
| /// | ||
| /// @description Checks that for expression of the form `E1 is! S`, | ||
| /// `true(N) = promote(E1, factor(T, S), after(E1))` and | ||
| /// `false(N) = promote(E1, S, after(E1))`. Test `factor(T, S)` for the case | ||
| /// `T` is `R?` and `S` is not subtype of `Null`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| main() { | ||
| int? i = 2 > 1 ? null : 42; | ||
| if (i is! int) { | ||
| i.expectStaticType<Exactly<Null>>(); | ||
| } else { | ||
| i.expectStaticType<Exactly<int>>(); | ||
| } | ||
| } |
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,37 @@ | ||
| // 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 negated instance check If `N` is an expression of the form | ||
| /// `E1 is! S` where the static type of `E1` is `T` then: | ||
| /// - Let `before(E1) = before(N)` | ||
| /// - If `T` is a bottom type, then: | ||
| /// - Let `true(N) = after(E1)`. | ||
| /// - Let `false(N) = unreachable(after(E1))`. | ||
| /// - Otherwise: | ||
| /// - Let `true(N) = promote(E1, factor(T, S), after(E1))` | ||
| /// - Let `false(N) = promote(E1, S, after(E1))` | ||
| /// | ||
| /// @description Checks that for expression of the form `E1 is! S`, | ||
| /// `true(N) = promote(E1, factor(T, S), after(E1))` and | ||
| /// `false(N) = promote(E1, S, after(E1))`. Test `factor(T, S)` for the case | ||
| /// `T` is `FutureOr<R>` and `Future<R> <: S`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import 'dart:async'; | ||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| class C {} | ||
|
|
||
| test(FutureOr<C> foc) async { | ||
| if (foc is! Future<C>) { | ||
| foc.expectStaticType<Exactly<C>>(); | ||
| } else { | ||
| foc.expectStaticType<Exactly<Future<C>>>(); | ||
| } | ||
| } | ||
|
|
||
| main() { | ||
| test(C()); | ||
| test(Future<C>.value(C())); | ||
| } |
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,37 @@ | ||
| // 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 negated instance check If `N` is an expression of the form | ||
| /// `E1 is! S` where the static type of `E1` is `T` then: | ||
| /// - Let `before(E1) = before(N)` | ||
| /// - If `T` is a bottom type, then: | ||
| /// - Let `true(N) = after(E1)`. | ||
| /// - Let `false(N) = unreachable(after(E1))`. | ||
| /// - Otherwise: | ||
| /// - Let `true(N) = promote(E1, factor(T, S), after(E1))` | ||
| /// - Let `false(N) = promote(E1, S, after(E1))` | ||
| /// | ||
| /// @description Checks that for expression of the form `E1 is! S`, | ||
| /// `true(N) = promote(E1, factor(T, S), after(E1))` and | ||
| /// `false(N) = promote(E1, S, after(E1))`. Test `factor(T, S)` for | ||
| /// the case `T` is `FutureOr<R>` and `R <: S`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import 'dart:async'; | ||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| class C {} | ||
|
|
||
| test(FutureOr<C> foc) async { | ||
| if (foc is! C) { | ||
| foc.expectStaticType<Exactly<Future<C>>>(); | ||
| } else { | ||
| foc.expectStaticType<Exactly<C>>(); | ||
| } | ||
| } | ||
|
|
||
| main() { | ||
| test(C()); | ||
| test(Future<C>.value(C())); | ||
| } |
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,28 @@ | ||
| // 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 negated instance check If `N` is an expression of the form | ||
| /// `E1 is! S` where the static type of `E1` is `T` then: | ||
| /// - Let `before(E1) = before(N)` | ||
| /// - If `T` is a bottom type, then: | ||
| /// - Let `true(N) = after(E1)`. | ||
| /// - Let `false(N) = unreachable(after(E1))`. | ||
| /// - Otherwise: | ||
| /// - Let `true(N) = promote(E1, factor(T, S), after(E1))` | ||
| /// - Let `false(N) = promote(E1, S, after(E1))` | ||
| /// | ||
| /// @description Checks that if `T` is a bottom type then `true(N) = after(E1)`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| test(x) { | ||
| int i; | ||
| if (x is! Never) { | ||
| i = 42; | ||
| } | ||
| i; // Definitely assigned. | ||
| } | ||
|
|
||
| main() { | ||
| test(null); | ||
| } |
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,33 @@ | ||
| // 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 negated instance check If `N` is an expression of the form | ||
| /// `E1 is! S` where the static type of `E1` is `T` then: | ||
| /// - Let `before(E1) = before(N)` | ||
| /// - If `T` is a bottom type, then: | ||
| /// - Let `true(N) = after(E1)`. | ||
| /// - Let `false(N) = unreachable(after(E1))`. | ||
| /// - Otherwise: | ||
| /// - Let `true(N) = promote(E1, factor(T, S), after(E1))` | ||
| /// - Let `false(N) = promote(E1, S, after(E1))` | ||
| /// | ||
| /// @description Checks that if `T` is a bottom type then | ||
| /// `false(N) = promote(E1, factor(T, S), after(E1))`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| test(x) { | ||
| late int i; | ||
| if (x is! Never) { | ||
| } else { | ||
| i = 42; | ||
| } | ||
| i; // Definitely unassigned. | ||
| //^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| main() { | ||
| print(test); | ||
| } |
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.