-
Notifications
You must be signed in to change notification settings - Fork 28
#3057. Add more for-statement tests #3110
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
3 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
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 for statement: If `N` is a for statement of the form | ||
/// `for (D; C; U) S,` then: | ||
/// - Let `before(D) = before(N)`. | ||
/// - Let `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))` | ||
/// - Let `before(S) = split(true(C))`. | ||
/// - Let `before(U) = merge(after(S), continue(S))`. | ||
/// - Let `after(N) = inheritTested(join(false(C), unsplit(break(S))), after(U))` | ||
/// | ||
/// @description Checks that | ||
/// `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))`. Test | ||
/// that if variable is assigned `after(D)` then it is definitely assigned | ||
/// `before(C)`. | ||
/// @author [email protected] | ||
|
||
test1() { | ||
int n; | ||
for (n = 42; n > 0;) { // n definitely assigned | ||
break; | ||
} | ||
} | ||
|
||
test2() { | ||
int n; | ||
[ | ||
for (n = 42; n < 0;) | ||
0 | ||
]; | ||
} | ||
|
||
test3() { | ||
int n; | ||
<int, int>{ | ||
for (n = 42; n < 0;) | ||
0: 0 | ||
}; | ||
} | ||
|
||
main() { | ||
test1(); | ||
test2(); | ||
test3(); | ||
} |
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 for statement: If `N` is a for statement of the form | ||
/// `for (D; C; U) S,` then: | ||
/// - Let `before(D) = before(N)`. | ||
/// - Let `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))` | ||
/// - Let `before(S) = split(true(C))`. | ||
/// - Let `before(U) = merge(after(S), continue(S))`. | ||
/// - Let `after(N) = inheritTested(join(false(C), unsplit(break(S))), after(U))` | ||
/// | ||
/// @description Checks that | ||
/// `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))`. Test | ||
/// that `assignedIn(U)` is detected by flow analysis. | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// @author [email protected] | ||
|
||
test1() { | ||
late int n; | ||
for ( | ||
; | ||
() { | ||
if (1 > 2) { | ||
n; // possibly assigned | ||
} | ||
return true; | ||
}(); | ||
n = 42 | ||
) {} | ||
} | ||
|
||
test2() { | ||
late int n; | ||
[ | ||
for ( | ||
; | ||
() { | ||
if (1 > 2) { | ||
n; | ||
} | ||
return true; | ||
}(); | ||
n = 42 | ||
) | ||
0, | ||
]; | ||
} | ||
|
||
test3() { | ||
late int n; | ||
<int, int>{ | ||
for ( | ||
; | ||
() { | ||
if (1 > 2) { | ||
n; | ||
} | ||
return true; | ||
}(); | ||
n = 42 | ||
) | ||
0: 0, | ||
}; | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
} |
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,86 @@ | ||
// 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 for statement: If `N` is a for statement of the form | ||
/// `for (D; C; U) S,` then: | ||
/// - Let `before(D) = before(N)`. | ||
/// - Let `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))` | ||
/// - Let `before(S) = split(true(C))`. | ||
/// - Let `before(U) = merge(after(S), continue(S))`. | ||
/// - Let `after(N) = inheritTested(join(false(C), unsplit(break(S))), after(U))` | ||
/// | ||
/// @description Checks that | ||
/// `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))`. Test | ||
/// that `assignedIn(S)` is detected by flow analysis. | ||
/// @author [email protected] | ||
|
||
test1() { | ||
late int n; | ||
for ( | ||
; | ||
() { | ||
if (1 > 2) { | ||
n; // possibly assigned | ||
} | ||
return true; | ||
}(); | ||
) { | ||
n = 42; | ||
} | ||
} | ||
|
||
test2() { | ||
late int n; | ||
[ | ||
for ( | ||
; | ||
() { | ||
if (1 > 2) { | ||
n; | ||
} | ||
return true; | ||
}(); | ||
) | ||
n = 42, | ||
]; | ||
} | ||
|
||
test3() { | ||
late int n; | ||
<int, int>{ | ||
for ( | ||
; | ||
() { | ||
if (1 > 2) { | ||
n; | ||
} | ||
return true; | ||
}(); | ||
) | ||
n = 42: 0, | ||
}; | ||
} | ||
|
||
test4() { | ||
late int n; | ||
<int, int>{ | ||
for ( | ||
; | ||
() { | ||
if (1 > 2) { | ||
n; | ||
} | ||
return true; | ||
}(); | ||
) | ||
0: n = 42, | ||
}; | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
print(test4); | ||
} |
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,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 for statement: If `N` is a for statement of the form | ||
/// `for (D; C; U) S,` then: | ||
/// - Let `before(D) = before(N)`. | ||
/// - Let `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))` | ||
/// - Let `before(S) = split(true(C))`. | ||
/// - Let `before(U) = merge(after(S), continue(S))`. | ||
/// - Let `after(N) = inheritTested(join(false(C), unsplit(break(S))), after(U))` | ||
/// | ||
/// @description Checks that | ||
/// `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))`. Test | ||
/// that an assignment in `C` doesn't affect value of `before(D)`. | ||
/// @author [email protected] | ||
|
||
test1() { | ||
late int n; | ||
for (n; (n = 42) < 0;) { // Definitely unassigned | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
break; | ||
} | ||
} | ||
|
||
test2() { | ||
int n; | ||
[ | ||
for (n; (n = 42) < 0;) 0 | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
]; | ||
} | ||
|
||
test3() { | ||
int n; | ||
<int, int>{ | ||
for (n; (n = 42) < 0;) 0: 0 | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
} |
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,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 for statement: If `N` is a for statement of the form | ||
/// `for (D; C; U) S,` then: | ||
/// - Let `before(D) = before(N)`. | ||
/// - Let `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))` | ||
/// - Let `before(S) = split(true(C))`. | ||
/// - Let `before(U) = merge(after(S), continue(S))`. | ||
/// - Let `after(N) = inheritTested(join(false(C), unsplit(break(S))), after(U))` | ||
/// | ||
/// @description Checks that | ||
/// `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))`. Test | ||
/// that an assignment in `U` doesn't affect value of `before(D)`. | ||
/// @author [email protected] | ||
|
||
test1() { | ||
late int n; | ||
for (n;; n = 42) { // Definitely unassigned | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
break; | ||
} | ||
} | ||
|
||
test2() { | ||
int n; | ||
[ | ||
for (n; ;n = 42) 0 | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
]; | ||
} | ||
|
||
test3() { | ||
int n; | ||
<int, int>{ | ||
for (n; ;n = 42) 0: 0 | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
} |
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,64 @@ | ||
// 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 for statement: If `N` is a for statement of the form | ||
/// `for (D; C; U) S,` then: | ||
/// - Let `before(D) = before(N)`. | ||
/// - Let `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))` | ||
/// - Let `before(S) = split(true(C))`. | ||
/// - Let `before(U) = merge(after(S), continue(S))`. | ||
/// - Let `after(N) = inheritTested(join(false(C), unsplit(break(S))), after(U))` | ||
/// | ||
/// @description Checks that | ||
/// `before(C) = conservativeJoin(after(D), assignedIn(N), capturedIn(N))`. Test | ||
/// that an assignment in `S` doesn't affect value of `before(D)`. | ||
/// @author [email protected] | ||
|
||
test1() { | ||
late int n; | ||
for (n;;) { // Definitely unassigned | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
n = 42; | ||
break; | ||
} | ||
} | ||
|
||
test2() { | ||
int n; | ||
[ | ||
for (n; ;) n = 42 | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
]; | ||
} | ||
|
||
test3() { | ||
int n; | ||
<int, int>{ | ||
for (n; ;) n = 42: 0 | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
} | ||
|
||
test4() { | ||
int n; | ||
<int, int>{ | ||
for (n; ;) 0: n = 42 | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
print(test4); | ||
} |
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.