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

dart2js not setting default function field #36222

Closed
hterkelsen opened this Issue Mar 14, 2019 · 3 comments

Comments

Projects
None yet
5 participants
@hterkelsen
Copy link
Member

hterkelsen commented Mar 14, 2019

I have the following program:

typedef int BinaryFunc(int x, int y);

class A {
  const A({this.foo = A.defaultFoo});

  static int defaultFoo(int x, int y) {
    return x + y;
  }

  final BinaryFunc foo;
}

class B<T> {
  T get item => _item;
  T _item;
}

class C extends B<A> {
  bar() {
    print(item.foo(1, 2));
  }
}

class Box {
  final B<Object> b;
  Box(B<Object> b) : this.b = b;

  update(Object o) {
    b._item = o;
  }
}

main() {
  var c = C();
  var box1 = Box(c);

  var b = B<int>();
  var box2 = Box(b);

  box2.update(3);
  box1.update(A());

  c.bar();
}

This code works fine in older versions of dart2js (works on Dartpad), but fails on the most current version of dart2js (Dart-to-JavaScript compiler (dart2js) version: 2.2.1-edge.5e1397fc4e7dd8e32a79252a7e780d120c939392).

dart2js emits this code for the class A:

  T.A.prototype = {
    foo$2: function(arg0, arg1) {
      return this.foo.call$2(arg0, arg1);
    }
  };

but it never sets this.foo so when c.bar() is run, it crashes with:

TypeError: Cannot read property 'call$2' of undefined
         throw e;
         ^
TypeError: Cannot read property 'call$2' of undefined
   at A.foo$2 (out.js:1464:23)
   at main (out.js:1221:33)
   at action (/usr/local/google/home/het/Projects/dart/sdk/sdk/lib/_internal/js_runtime/lib/preambles/d8.js:275:31)
   at eventLoop (/usr/local/google/home/het/Projects/dart/sdk/sdk/lib/_internal/js_runtime/lib/preambles/d8.js:258:9)
   at self.dartMainRunner (/usr/local/google/home/het/Projects/dart/sdk/sdk/lib/_internal/js_runtime/lib/preambles/d8.js:276:5)
   at out.js:1534:7
   at out.js:1520:7
   at dartProgram (out.js:1531:5)
   at out.js:1538:3

@kevmoo kevmoo added the p1-high label Mar 14, 2019

@kevmoo kevmoo added this to the Dart2.2.1 milestone Mar 14, 2019

@vsmenon vsmenon modified the milestones: Dart2.2.1, Dart2.3 Mar 14, 2019

@vsmenon

This comment has been minimized.

Copy link
Member

vsmenon commented Mar 14, 2019

@kevmoo - I've been folding 2.2.1 issues to 2.3.

@sigmundch

This comment has been minimized.

Copy link
Member

sigmundch commented Mar 14, 2019

@johnniwinther - I bisected this and found that this started failing with 1720704

@johnniwinther johnniwinther self-assigned this Mar 15, 2019

@johnniwinther

This comment has been minimized.

Copy link
Member

johnniwinther commented Mar 15, 2019

@dart-bot dart-bot closed this in eb6f1b6 Mar 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.