You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Note I have a very amateur understanding of flow analysis)
Take this code:
voidf(String? s, List<int> lengths) {
for (;;) {
if (s ==null) return;
if (1==2) break;
s ="not null";
}
s.length; // OK// The property 'length' can't be unconditionally accessed because the receiver can be null.
lengths.any((e) => e == s.length);
}
So after the for loop, s is promoted to String. s.length is then OK. But later on, in a closure, s.length is not OK; analyzer and CFE say that s is a String?.
I know that there is not a lot of flow analysis or promotion going on within closures, but there is some. In this simpler example, which contains zero re-assignments, we get no errors:
voidf2(String? s, List<int> lengths) {
if (s ==null) return;
lengths.any((e) => e == s.length);
}
So I'm guess something about the re-assignment (with a String value, note) throws a lot of flow analysis or promotion out the window.
Bug? Feature? I perused for other promotion bugs but didn't find anything like this.
The text was updated successfully, but these errors were encountered:
srawlins
changed the title
local variable losses promoted type in closure, even when closure is followed by zero assignments
local variable looses promoted type in closure, in the presence of a re-assignment
Jun 9, 2021
(Note I have a very amateur understanding of flow analysis)
Take this code:
So after the for loop,
s
is promoted toString
.s.length
is then OK. But later on, in a closure,s.length
is not OK; analyzer and CFE say thats
is aString?
.I know that there is not a lot of flow analysis or promotion going on within closures, but there is some. In this simpler example, which contains zero re-assignments, we get no errors:
So I'm guess something about the re-assignment (with a
String
value, note) throws a lot of flow analysis or promotion out the window.Bug? Feature? I perused for other promotion bugs but didn't find anything like this.
The text was updated successfully, but these errors were encountered: