-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
dart-model-analyzer-specIssues with the analyzer's implementation of the language specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.
Description
The following code is accepted by the CFE but rejected by the analyzer:
extension E on Null {
int f(dynamic d) => 0;
}
int test(int? i) {
i = 0; // promotes `i` to `int`
E(null)?.f(i = null); // doesn't demote because `i = null` is unreachable
return i; // ok because `i` is promoted to `int`
}
main() {}The analyzer's error message is:
error • test.dart:8:10 • A value of type 'int?' can't be returned from the function 'test' because it has a return type of 'int'. • return_of_invalid_type
I believe what's happening is that the CFE is (correctly) passing the type of the target of the extension override (Null in this case) to FlowAnalysis.nullAwareAccess_rightBegin. Therefore, flow analysis concludes that i = null is unreachable, so i is not demoted. Whereas the analyzer is passing the type dynamic to FlowAnalysis.nullAwareAccess_rightBegin, so flow analysis doesn't know that i = null is unreachable, and so it demotes i to int?, and the return statement is in error.
I'll work on a fix.
FMorschel
Metadata
Metadata
Assignees
Labels
dart-model-analyzer-specIssues with the analyzer's implementation of the language specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.