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

some member names likely don't work right for types with "call" method #27647

Closed
jmesserly opened this issue Oct 21, 2016 · 5 comments
Closed
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dev-compiler

Comments

@jmesserly
Copy link

jmesserly commented Oct 21, 2016

(moved from dart-archive/dev_compiler#593)

In particular, those that are inherited from JS Functions, like "name" and "length".

We also allow shadowing methods like "call" and "apply". This may cause problems in our runtime, or in JS code that gets these objects. We should probably symbolize call/apply to avoid collision.

@jmesserly
Copy link
Author

CC @alan-knight who saw a related issue

@vsmenon vsmenon added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jan 9, 2017
@greglittlefield-wf
Copy link
Contributor

We needed to work around this issue to use the DDC, so I implemented a runtime fix to the issue with the name accessor until the underlying issue is fixed, if anyone's interested:

It's hacky and brittle and I'm not super proud of it, but it gets the job done if you really need to work around this issue.

@jmesserly
Copy link
Author

CC @vsmenon @grouma -- this is the bug for some member names not working on "callable" classes

@jmesserly
Copy link
Author

Here's a test demonstrating the issues:

class Foo {
  final name = 'FOO!';
  final length = 123;
  call() => 'hello world';
  bind(int x) => x + 40;
  apply(x, y) => 'called apply($x, $y)';
}
main() {
  var f = new Foo();
  print(f());
  // Fails because Dart sets these with `this.name =` and `this.length =` and
  // that's ignored because the data properties are not writable
  // (http://www.ecma-international.org/ecma-262/6.0/#sec-function.length)
  print(f.name);
  print(f.length);
  // works because Dart method shadows the JS ones (probably breaks JS interop)
  print(f.apply(1, 2));
  print(f.bind(2));
  // This happens to work because DDC checks `f instanceof Function` rather than
  // `typeof f == "function"`, causing it to tearoff the `call` method rather
  // than directly calling `f.apply`.
  print((f as dynamic)());
}

One way to fix this would be to treat classes with call methods as a "native type" because they are instances of JS functions at runtime. But that's a pretty blunt instrument.

@jmesserly
Copy link
Author

this was fixed. callable classes are not subtypes of function types any longer, so we do not represent them the same way in JS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dev-compiler
Projects
None yet
Development

No branches or pull requests

3 participants