Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions TypeSystem/flow-analysis/reachability_break_A05_t01.dart
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 Break statement: If `N` is a statement of the form `break [L];`,
/// then:
/// - Let `S` be the statement targeted by the `break`. If `L` is not present,
/// this is the innermost `do`, `for`, `switch`, or `while` statement.
/// Otherwise it is the `do`, `for`, `switch`, or `while` statement with a
/// label matching L.
/// - Update `break(S) = join(break(S), before(N))`.
/// - Let `after(N) = unreachable(before(N))`.
///
/// @description Checks that if some type `T` is made a type of interest
/// `before(N)` then the variable can be promoted to `T` in `after(N)`.
/// @author sgrekhov22@gmail.com

class S {}

class T extends S {
int answer() => 42;
}

test1() {
S s = S();
for (int j = 0; j < 1; j++) {
if (s is T) {} // Make `T` a type of interest
break;
// Unreachable, but does support promotion.
s = T();
s.answer();
}
}

test2() {
S s = S();
for (var j in []) {
if (s is T) {}
break;
s = T();
s.answer();
}
}

test3() {
S s = S();
do {
if (s is T) {}
break;
s = T();
s.answer();
} while (1 > 2);
}

test4() {
S s = S();
int i = 0;
while (i < 1) {
i++;
if (s is T) {}
break;
s = T();
s.answer();
}
}

test5() {
S s = S();
switch (42) {
case 1:
break;
case 42:
if (s is T) {}
break;
s = T();
s.answer();
}
}

main() {
test1();
test2();
test3();
test4();
test5();
}
101 changes: 101 additions & 0 deletions TypeSystem/flow-analysis/reachability_break_A05_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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 Break statement: If `N` is a statement of the form `break [L];`,
/// then:
/// - Let `S` be the statement targeted by the `break`. If `L` is not present,
/// this is the innermost `do`, `for`, `switch`, or `while` statement.
/// Otherwise it is the `do`, `for`, `switch`, or `while` statement with a
/// label matching L.
/// - Update `break(S) = join(break(S), before(N))`.
/// - Let `after(N) = unreachable(before(N))`.
///
/// @description Checks that if some type `T` is made a type of interest
/// `before(N)` then the variable can be promoted to `T` in `after(N)`.
/// @author sgrekhov22@gmail.com

class S {}

class T extends S {
int answer() => 42;
}

test1() {
S s = S();
L:
for (int j = 0; j < 1; j++) {
for (int j = 0; j < 1; j++) {
if (s is T) {} // Make `T` a type of interest
break L;
// Unreachable, but does support promotion.
s = T();
s.answer();
}
}
}

test2() {
S s = S();
L:
for (var i in []) {
for (var j in []) {
if (s is T) {}
break L;
s = T();
s.answer();
}
}
}

test3() {
S s = S();
L:
do {
do {
if (s is T) {}
break L;
s = T();
s.answer();
} while (1 > 2);
} while (1 > 2);
}

test4() {
S s = S();
int i = 0;
L:
while (i < 1) {
while (i < 1) {
i++;
if (s is T) {}
break L;
s = T();
s.answer();
}
}
}

test5() {
S s = S();
L:
for (;;) {
switch (42) {
case 1:
break;
case 42:
if (s is T) {}
break L;
s = T();
s.answer();
}
}
}

main() {
test1();
test2();
test3();
test4();
test5();
}
101 changes: 101 additions & 0 deletions TypeSystem/flow-analysis/reachability_break_A05_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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 Break statement: If `N` is a statement of the form `break [L];`,
/// then:
/// - Let `S` be the statement targeted by the `break`. If `L` is not present,
/// this is the innermost `do`, `for`, `switch`, or `while` statement.
/// Otherwise it is the `do`, `for`, `switch`, or `while` statement with a
/// label matching L.
/// - Update `break(S) = join(break(S), before(N))`.
/// - Let `after(N) = unreachable(before(N))`.
///
/// @description Checks that if some type `T` is made a type of interest
/// `after(N)` then the variable cannot be promoted to `T` in `before(N)`.
/// @author sgrekhov22@gmail.com

class S {}

class T extends S {
int answer() => 42;
}

test1() {
S s = S();
for (int j = 0; j < 2; j++) {
s = T();
s.answer();
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
break;
// Unreachable, but does support promotion.
if (s is T) {} // Make `T` a type of interest
}
}

test2() {
S s = S();
for (var j in []) {
s = T();
s.answer();
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
break;
if (s is T) {}
}
}

test3() {
S s = S();
do {
s = T();
s.answer();
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
break;
if (s is T) {}
} while (1 > 2);
}

test4() {
S s = S();
int i = 0;
while (i < 2) {
i++;
s = T();
s.answer();
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
break;
if (s is T) {}
}
}

test5() {
S s = S();
switch (42) {
case 1:
break;
case 42:
s = T();
s.answer();
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
break;
if (s is T) {}
}
}

main() {
print(test1);
print(test2);
print(test5);
print(test4);
print(test5);
}
Loading