-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[NNBD] No error in Analyzer when non-nullable function may return null #42568
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 result of |
I believe this is concerned with function literal return type inference: If the invocation of
The rules here for the computation of the 'actual returned type' do not take the normal completion (that is: we reach the end of the function) into account, so I believe the CFE is correct and the analyzer takes an extra step which is not specified (in adding I also think it would make sense to do as the analyzer says, in which case we should add an extra case to the rules about computing the actual return type. |
Second thought: We should stick to the current rules. ;-) The local function void main() {
var b = true;
f() {
if (b) return 1;
}
g() {
if (b) return 1;
if (!b) return null;
}
} The point is that we do allow an explicit The current rules are giving the same treatment to the function literal as we're giving local functions (and no other functions are subject to return type inference based on the body). So the CFE behavior is the consistent behavior. |
It seems that this is a moving target, as discussion is continues in dart-lang/language#1063. |
@scheglov, @sgrekhov, with dart-lang/language#1063 closed I believe we can conclude that the analyzer works as intended: The normal completion gives rise to a nullable inferred return type for the function literal, and there is no error when the return statement is checked. So I'll close this. |
The following code produces no issues in Analyzer but a compile error in CFE
CFE output is
There must be a compile error in Analyzer as well
Dart VM version: 2.9.0-20.0.dev (dev) (Wed Jul 1 11:29:16 2020 +0200) on "windows_x64"
The text was updated successfully, but these errors were encountered: