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

fix checks for dynamic calls #7

Closed
sigmundch opened this issue Dec 20, 2014 · 3 comments
Closed

fix checks for dynamic calls #7

sigmundch opened this issue Dec 20, 2014 · 3 comments

Comments

@sigmundch
Copy link
Contributor

Copied from John:

Consider:

class M {
 call(x,y) => x+y;
}
main() {
 M m = new M();
 print(m(1,2)); // works
 print(m(1,2,3)); // NoSuchMethodError at runtime. analyzer fails to catch
 print(m.call(1,2,3)); // analyzer correctly detects this
}

This blows up due to wrong number of arguments at runtime. However, I don't see any warnings or errors from dart2js or dartanalyzer.
DDC does not really catch this either. It is treated as dynamic dispatch and allowed, for some reason, even though we could've caught it statically.

Turns out that in checker.dart we only look at:

 if (type.isDynamic || type.isDartCoreFunction || type is! FunctionType) { ...

we should additionaly check if the type implements call and use it's type instead:

if (type is InterfaceType) {
  var callMethod = type.lookUpMethod("call", _current.library);
  if (callMethod != null) type = callMethod.type;
}
...
@jmesserly
Copy link
Contributor

Yeah. Interesting to check some corner cases too, like obj.method(123). Where obj.method is a getter that returns an object with 'call' (I think that works, and we should be able to statically analyze it)

@vsmenon
Copy link
Contributor

vsmenon commented Jan 14, 2015

@leafpetersen is adding support for call methods. Not clear that's the only issue here.

@leafpetersen
Copy link
Contributor

The analyzer seems to have fixed the issue that allows m(1, 2, 3). There is another bug which seems to cause it to treat the return types incorrectly (dartbug.com/23252). I have a CL pending which fixes the dynamic dispatch issue.

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

No branches or pull requests

4 participants