Skip to content

Invoking emulated functions implemented using noSuchMethod sometimes fails in DDC #29904

Closed
@greglittlefield-wf

Description

@greglittlefield-wf

In the following code, invoking f2 throws an error.

class FunctionEmulator implements Function {
  call(a, b);
  noSuchMethod(i) => 'NSM ${i.positionalArguments}';
}

getF() => new FunctionEmulator();

main() {
  var f1 = new FunctionEmulator();
  print(f1(1, 2));

  var f2 = getF();
  print(f2(3, 4));
}

Here's the full output of executing this program:

NSM [1, 2]
require.js:143 Uncaught TypeError: Cannot read property 'noSuchMethod' of undefined
    at call (example__list__main.js:20)
    at Object.dart._checkAndCall (dart_sdk.js:2269)
    at Object.dart.dcall (dart_sdk.js:2293)
    at Object.list__main.main (example__list__main.js:42)
    at main.dart.bootstrap.js:97
    at Object.execCb (require.js:1696)
    at Module.check (require.js:878)
    at Module.<anonymous> (require.js:1139)
    at require.js:134
    at require.js:1189

Looking at the output, it seems that the second one uses dart.dcall:

    let f1 = new list__main.FunctionEmulator.new();
    core.print(f1(1, 2));
    let f2 = list__main.getF();
    core.print(dart.dcall(f2, 3, 4));

It's worth noting that adding a return type getF results in dart.dcall not being used, and the example works as expected:

-getF() => new FunctionEmulator();
+FunctionEmulator getF() => new FunctionEmulator();

This issue is present in Dart 1.24.0 and 1.25.0-dev.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dev-compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions