Skip to content

[dart:js_interop/dart2wasm] Missing type parameter check in exported generic callback #54314

@srujzs

Description

@srujzs
import 'dart:js_interop';

@JS('jsFunction')
external void callJsFunction(JSAny? val);

@JS()
external set jsFunction(JSFunction f);

void main() {
  void test<T extends JSAny?>() {
    jsFunction = ((T t) {
      return t;
    }).toJS;
    callJsFunction(null);
  }

  test<JSAny>();

  void test2<T extends JSAny?>() {
    final f = (T t) {};
    (f as Function)(null);
  }

  test2<JSNumber>();
}

test<JSAny> does not produce any errors, while test2<JSNumber> does the correct check on the parameter.

I had to disable some checks and remove some casts from the transformer to get a third test to work:

  void test3<T extends int?>() {
    jsFunction = ((T t) {
      return t;
    }).toJS;
    callJsFunction(null);
  }

  test3<int>();

but this also does not do a type-check, indicating that something about exporting the function is affecting the type-checking.

The callback should be called in the trampoline function, which is in Dart, so this shouldn't be an issue of the error escaping through JS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart2wasmIssues for the dart2wasm compiler.web-js-interopIssues that impact all js interop

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions