Skip to content
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

Adjust function literal return type inference to avoid spurious null #4210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Dec 17, 2024

See dart-lang/sdk#59669 where this topic came up. Thanks to @chiholai-sanasofthk for spotting this issue!

This PR changes one item in the list of actions taken during function literal return type inference: A return; statement only adds Null to the return type in cases where the given function literal is a non-generator.

With the current version, Null is added to the return type also in cases like () sync* { yield 1; return; } such that this function literal gets the inferred return type Iterable<int?>. This is an unnecessary loss of typing precision because null is never actually added to the returned iterable. With this update, the inferred return type is Iterable<int>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant