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
The following line is marked as not safe: print(value / 2);
while it contained in if(not null) scope, and value is final parameter:
if (value !=null) {
print(value /2);
}
And I get an error:
The operator '/' can't be unconditionally invoked because the receiver can be 'null'.
Try adding a null check to the target ('!').dartunchecked_use_of_nullable_value
Do I miss some thing?
The text was updated successfully, but these errors were encountered:
Yes, support for promotion of instance variables is discussed here.
The fundamental reason why promotion of instance variables is not sound is that any instance variable (final or not, late or not) introduces a getter which can be overridden, and there is no reason to believe that this getter will return the same result if you call it multiple times.
classA {
finalint? i;
A(this.i);
}
classBimplementsA {
bool useNull =true;
int?get i => (useNull =!useNull) ?null:0;
}
voidmain() {
var a =B();
if (a.i !=null) print(a.i); // 'null'.
}
I'll close this issue because it's all working as intended. We do have an ongoing effort to introduce support for promotion of instance variables (or getters) in certain situations. See https://dart-review.googlesource.com/c/sdk/+/262865 for the situation where the instance variable is private. See #1518 for a proposal that enables promotion of getters in a more general manner.
Look the following part of code:
The following line is marked as not safe:
print(value / 2);
while it contained in if(not null) scope, and value is final parameter:
And I get an error:
Do I miss some thing?
The text was updated successfully, but these errors were encountered: