Skip to content

DDC NoSuchMethodError when using non-external factory or static methods on all package:js classes #43527

Open
@evanweible-wf

Description

@evanweible-wf

pubspec.yaml

environment:
  sdk: ">=2.7.0 <3.0.0"

dev_dependencies:
  build_runner: any
  build_web_compilers: any
  js: any

web/main.dart

@JS()
library main;

import 'package:js/js.dart';

@anonymous
@JS()
abstract class Foo {
  external String get bar;
  external factory Foo({String bar});
  factory Foo.namedFactory() => Foo(bar: '!!');
}

void main() {
  print(Foo(bar: 'baz').bar); // Prints "baz"
  Foo.namedFactory(); // Throws a "NoSuchMethodError"
}

When built with DDC, running the above throws this error:

main.dart:16 Uncaught 
NoSuchMethodError: tried to call a non-function, such as null: 'dart.global.Foo' at main.dart 16:28                       main$
main$	@	main.dart:16
(anonymous)	@	main.dart.bootstrap.js:266
window.$dartRunMain	@	main.dart.bootstrap.js:265
(anonymous)	@	VM259:1
runMain	@	client.js:8758
(anonymous)	@	client.js:22459
(anonymous)	@	client.js:3802
call$2	@	client.js:10996
_asyncStartSync	@	client.js:3766
$call$body$main__closure	@	client.js:22471
call$1	@	client.js:22398
_rootRunUnary	@	client.js:4136
runUnary$2$2	@	client.js:12301
runUnaryGuarded$1$2	@	client.js:12233
_sendData$1	@	client.js:11784
perform$1	@	client.js:11936
call$0	@	client.js:11985
_microtaskLoop	@	client.js:3969
_startMicrotaskLoop	@	client.js:3975
call$1	@	client.js:10865
invokeClosure	@	client.js:1204
(anonymous)	@	client.js:1223
childList (async)		
call$1	@	client.js:10875
_scheduleAsyncCallback	@	client.js:3989
_rootScheduleMicrotask	@	client.js:4183
scheduleMicrotask	@	client.js:4018
schedule$1	@	client.js:11967
_addPending$1	@	client.js:11775
_sendData$1	@	client.js:11607
add$1	@	client.js:11507
_onIncomingMessage$1	@	client.js:22011
eval	@	VM242:3
invokeClosure	@	client.js:1204
(anonymous)	@	client.js:1223

This works as expected when building with dart2js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-dev-compilerweb-js-interopIssues that impact all js interopweb-triage-1priority assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions