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

Typedef with untyped args appear to generate spurious downcast messages #10

Closed
jacob314 opened this issue Dec 23, 2014 · 5 comments
Closed

Comments

@jacob314
Copy link
Contributor

Maybe I am confused about where the downcast is coming from but I don't understand why this generates a downcast.

typedef String StringProvider(data);

void main() {
  List<StringProvider> providers = <StringProvider>[(_) => "foo", (_) => "bar"];
  String someString = providers[1]("arg ignored"); // Generates DownCast warning
}
@vsmenon
Copy link
Contributor

vsmenon commented Dec 23, 2014

Hmm, I think the DownCast may be due to the static type of (_) => "bar" being dynamic -> dynamic. I.e., in our the type system (both Dart and our stricter one), the return type of a lambda (=>) is dynamic.

So, the DownCast would be from dynamic -> dynamic (the type of the function literals) to dynamic -> String (StringProvider). This should be a coercion though I think.

@jacob314
Copy link
Contributor Author

The DownCast warning I get is on the line invoking the StringProvider not the one defining it.
The source code I based the repro example from defined the StringProvider is a separate file.

@vsmenon
Copy link
Contributor

vsmenon commented Dec 23, 2014

What happens if you break that into two lines:
StringProvider provider = providers[1];
String someString = provider("arg ignored");
?

Wondering which one it's complaining about....

@vsmenon
Copy link
Contributor

vsmenon commented Jan 13, 2015

This error is still here. This is the warning:
providers[1]("arg ignored") (dynamic) will need runtime check to cast to type String

If that last line is rewritten as follows:
var provider = providers[1];
String someString = provider("arg ignored");
no warning. It appears we're not properly checking / propagating types in the first case.

@vsmenon
Copy link
Contributor

vsmenon commented Aug 12, 2015

This example does the right thing now - no down cast.

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