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
I'm not sure if there is an existing issue for this, I wasn't able to find one.
Consider the following program:
voidmain() {
final items = [6, null, 1, 2, 3, 4, 5];
int? item;
while ((item = items.removeLast()) !=null) {
// item should be promoted to int, instead we get the following error:// The operator '*' can't be unconditionally invoked because the receiver can be 'null'.print(item *100);
}
if ((item = items.removeLast()) !=null) {
// item should be promoted to int, instead we get the following error:// The operator '*' can't be unconditionally invoked because the receiver can be 'null'.print(item *100);
}
}
It would seem reasonable for a condition of the form (a = b) != null to promote a from SomeType? to SomeType, assuming a is a local variable.
Promotions should also work with (a = b) == null, (a = b) is SomeType, (a = b) is! SomeType.
Promotions should probably also apply when using ??= as in (a ??= b) != null.
And when doing multiple assignments as in (a = b = c = d) != null where a and b and c are all local variables they would all be promoted.
The text was updated successfully, but these errors were encountered:
I'm not sure if there is an existing issue for this, I wasn't able to find one.
Consider the following program:
It would seem reasonable for a condition of the form
(a = b) != null
to promotea
fromSomeType?
toSomeType
, assuminga
is a local variable.Promotions should also work with
(a = b) == null
,(a = b) is SomeType
,(a = b) is! SomeType
.Promotions should probably also apply when using
??=
as in(a ??= b) != null
.And when doing multiple assignments as in
(a = b = c = d) != null
wherea
andb
andc
are all local variables they would all be promoted.The text was updated successfully, but these errors were encountered: