Skip to content

Promotion and ?? #1658

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

Open
lrhn opened this issue May 31, 2021 · 3 comments
Open

Promotion and ?? #1658

lrhn opened this issue May 31, 2021 · 3 comments
Labels
flow-analysis Discussions about possible future improvements to flow analysis question Further information is requested

Comments

@lrhn
Copy link
Member

lrhn commented May 31, 2021

Was just informed that bool? foo = ...; if (foo ?? false) print(!foo); does not promote foo to non-null in the "then" branch, even though the otherwise equivalent if (foo != null ? foo : false) print(!foo); does.

main() {
 bool? foo = true as dynamic;
 if (foo != null ? foo : false) print(!foo);  // No error here.
 if (foo ?? false) print(!foo);
 //                      ^ error here!
}

Is this deliberate, a flaw in the analysis spec, or a bug?

@lrhn lrhn added the question Further information is requested label May 31, 2021
@leafpetersen
Copy link
Member

This is discussed here: #1224 . This issue is largely a duplicate, but I since the discussion in #1224 is not very discoverable, I'll leave this issue open as a better named re-direct to that discussion.

@leafpetersen leafpetersen added the flow-analysis Discussions about possible future improvements to flow analysis label Jun 2, 2021
@leafpetersen
Copy link
Member

cc @stereotype441

@amir-msh
Copy link

amir-msh commented Jun 25, 2021

As a temporary solution until the Dart team solve it :
print(!foo!);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flow-analysis Discussions about possible future improvements to flow analysis question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants