-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.feature-null-aware-elementsImplementation of the Null-aware elements featureImplementation of the Null-aware elements featuretype-questionA question about expected behavior or functionalityA question about expected behavior or functionality
Description
Consider the following program.
class A {
int? get x {
print("Getter 'x' called.");
return 0;
}
foo() {
return [0, if (x != null) x!, 1];
}
}
main() {
new A().foo();
}
In that program, replacing if (x != null) x!
with ?x
changes the observable behavior. In the former case it will print the line Getter 'x' called.
twice, and in the latter — once. This is the reason behind the linter not offering such a rewrite when getters are tested for being null.
However, as hinted by #61122, it might go against the intuition of the programmer, since in practice many getters are stable and don't have any side effects.
Should our tooling account for such user expectations and possibly provide a hint or address it in any other way?
kevmoo
Metadata
Metadata
Assignees
Labels
area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.feature-null-aware-elementsImplementation of the Null-aware elements featureImplementation of the Null-aware elements featuretype-questionA question about expected behavior or functionalityA question about expected behavior or functionality