Closed
Description
- Dart SDK 2.12.2
- Reproducible in DartPad on Chrome
Consider the following snippet:
abstract class Identifier {
Uri? get moduleUri;
}
void f(Identifier? id) {
if (id?.moduleUri != null) {
print(id.moduleUri);
}
}
Currently the id.moduleUrl
within the body of the if statement produces an error:
line 7 • The property 'moduleUri' can't be unconditionally accessed because the receiver can be 'null'.
Try making the access conditional (using '?.') or adding a null check to the target ('!').
The expression id?.moduleUri != null
can only be true if id
is non-null. Could the compiler/analyzer perform this type flow analysis in order to promote id
to a non-null type within the if statement?
Metadata
Metadata
Assignees
Labels
No labels