Closed as not planned
Description
@stereotype441 is the following expected? Why if type T
is made a type of interest in the increment part of the for(;;)
loop then a variable of type S
cannot be promoted to T
in the body of the loop but can be after it?
class S {}
class T extends S {
int answer() => 42;
}
test1() {
S s = S();
for (int i = 0; i < 1; s is T ? true : false, i++) {
s = T();
s.answer(); // Error. The method 'answer' isn't defined for the type 'S'.
}
}
test2() {
S s = S();
for (int i = 0; i < 1; s is T ? true : false, i++) {
}
s = T();
s.answer(); // Ok
}
Dart SDK version: 3.9.0-23.0.dev (dev) (Tue Apr 15 21:06:42 2025 -0700) on "windows_x64"