-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Nullability promotion issue with local variable usages in iterators #51183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The reason why The point is that the function literal We have had requests for an improved analysis of this situation. Perhaps it would be possible to recognize that the function object could not possibly be called at any point in time where In any case, you can help the flow analysis by introducing a new local variable whose value is never nullable: void main() {
final String? test;
final List<String> testList = [];
if (1 * 2 == 2) {
test = 'Yes';
} else {
test = null;
}
if (test != null) {
var test1 = test;
testList.removeWhere((e) => e.contains(test1));
}
} |
@stereotype441, I searched for an issue which is requesting improvements in the flow analysis of variables whose value is read (not written) in a local function object, but didn't find anything spot on. Are you aware of any such issue? Otherwise, I think we could move this issue to the language repository and make it the go-to issue for this feature request. |
This is a duplicate of dart-lang/language#1536, for which there is CL which makes the OP test pass, in sdk/277880 |
@asashour, that was exactly what I was looking for, thanks! |
Thanks! The request for promoting final expressions also looks great too. |
This tracker is for issues related to: Analyzer.
When I was developing in flutter_tools, I found a weird promotion with the nullability of a local variable.
A simple example for this issue:
I was wondering at this point why the variable cannot be proofed as non-null.
The text was updated successfully, but these errors were encountered: