Skip to content

upwards inference for block bodied lambda returns #25487

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

Closed
jmesserly opened this issue Jan 14, 2016 · 5 comments
Closed

upwards inference for block bodied lambda returns #25487

jmesserly opened this issue Jan 14, 2016 · 5 comments
Assignees
Labels
legacy-area-analyzer Use area-devexp instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug

Comments

@jmesserly
Copy link

From @leafpetersen

A minor annoyance that comes up now and then is that we don't do upwards inference to infer the return type of block-bodied closure literals. I don't think doing so would be too difficult - we could just keep track of the LUB of the static type of all of the returned values when we visit a function body.

@munificent
Copy link
Member

Huh, I could have sworn I filed an issue for this a while back but now I can't find it.

Either way, this was one of the biggest things I noticed when I converted a game of mine to be strong mode clean.

@leafpetersen
Copy link
Member

I think we (or I) closed out that bug when I implemented downwards inference for block bodied functions. This does indeed catch many cases, but there are situations (especially related to generic methods) where it doesn't. So for example:

List<int> o;
o.map((x) {return x + 1;});

At the point where we're doing downwards inference, we don't have a useful type to push down into the closure. Later on when we're instantiating the generic type parameters, we want to use the type of the closure to constrain the type arguments, but here the closure return type will just be dynamic unless we infer based on the returns.

@jmesserly jmesserly added P1 A high priority bug; for example, a single project is unusable or has many test failures and removed Priority-Medium labels Feb 22, 2016
@jmesserly
Copy link
Author

bumping to high, this is coming up in Angular code. Should be an easy fix right?

@jmesserly jmesserly self-assigned this Feb 22, 2016
@jmesserly
Copy link
Author

Might be worth cleaning up: _StaticTypeAnalyzer_computePropagatedReturnTypeOfFunction

It does a full tree traversal looking for return statements in the function. This is not necessary -- the relevant data could be recorded when we visit return statement as part of the original tree walk.

Fortunately, I think it only does the extra walk for local functions & lambdas.

@jmesserly
Copy link
Author

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants