Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Static type of "(x) => null" is computed as "(dynamic) => <bottom>" #47

Closed
vsmenon opened this issue Feb 13, 2015 · 6 comments
Closed

Comments

@vsmenon
Copy link
Contributor

vsmenon commented Feb 13, 2015

This should be (dynamic) => dynamic per spec as I understand it. Not sure if this is the analyzer or our mods to it.

@leafpetersen @bwilkerson @sigmundch

@jmesserly
Copy link
Contributor

@vsmenon does this still reproduce?

@vsmenon
Copy link
Contributor Author

vsmenon commented Aug 12, 2015

Yes, here's a repro:

void foo() {
  var f = (x) => null;
  f = (x) => "hello";
}

generates:

warning: [UninferredClosure] (x) => "hello" ((dynamic) → String) will need runtime check to cast to type (dynamic) → <bottom>

@jmesserly jmesserly self-assigned this Jan 22, 2016
@jmesserly
Copy link
Contributor

It looks like this is our inference. In some cases, like local var inference, we're careful not to accept bottom type. However this logic doesn't kick in consistently.

I'm guessing lambda expression return type and return statements have this problem. Upwards generic methods I think is okay, as we reject "bottom", which can happen sometimes naturally as a result of computing the lower/upper bounds. (edit: can confirm that upwards inference explicitly rejects bottom, if (inferredTypes[i].isBottom || ... ) { inferredTypes[i] = DynamicTypeImpl.instance; ...)

@jmesserly
Copy link
Contributor

BTW, bottom comes into play as the type of null, per the spec.

@jmesserly
Copy link
Contributor

haven't figured this out entirely, but my guess is that the static type () -> ⊥ for () => null comes from the spec type system. Probably our inference on function expressions should fix that up, in strong mode. Given that we have downward inference, I don't think we'll need to preserve that type as ⊥ (one possibility is to fix this for null itself, since the literal itself can be typed as anything from its context, not sure the spec type system treatment gets us anything. But we could also just fix it at the function expression level, since we already guard against ⊥ in our other inference.)

@jmesserly
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants