Skip to content

dart2js is generating a phantom type and throwing bogus errors about it #46455

@nex3

Description

@nex3

I'm seeing a very bizarre issue where dart2js is generating two distinct JS classes for a single Dart class, and throwing type errors because an object of one of these classes isn't an instance of the other. I haven't been able to find a minimal reproduction for this, so unfortunately you'll need to check out Dart Sass as a whole:

$ git clone git://github.com/sass/dart-sass --branch dart2js-type-error-repro
$ cd dart-sass
$ pub get
$ pub run grinder pkg-npm-dev
$ node repro.js

This will produce the following error:

result is SassNull: true
{
  err: Error: TypeError: Instance of 'SassNull': type 'SassNull' is not a subtype of type 'FutureOr<SassNull0>?'
      at Object._newRenderError (/home/nweiz/goog/sass/dart/build/npm/sass.dart.js:13677:19)
      at _render_closure1.call$2 (/home/nweiz/goog/sass/dart/build/npm/sass.dart.js:84642:21)
      at _RootZone.runBinary$3$3 (/home/nweiz/goog/sass/dart/build/npm/sass.dart.js:28567:18)
      at _FutureListener.handleError$1 (/home/nweiz/goog/sass/dart/build/npm/sass.dart.js:26968:26)
      at _Future__propagateToListeners_handleError.call$0 (/home/nweiz/goog/sass/dart/build/npm/sass.dart.js:27288:49)
      at Object._Future__propagateToListeners (/home/nweiz/goog/sass/dart/build/npm/sass.dart.js:4638:77)
      at _Future._completeError$2 (/home/nweiz/goog/sass/dart/build/npm/sass.dart.js:27111:9)
      at _AsyncAwaitCompleter.completeError$2 (/home/nweiz/goog/sass/dart/build/npm/sass.dart.js:26733:12)
      at Object._asyncRethrow (/home/nweiz/goog/sass/dart/build/npm/sass.dart.js:4436:17)
      at /home/nweiz/goog/sass/dart/build/npm/sass.dart.js:13315:20 {
    formatted: "Error: TypeError: Instance of 'SassNull': type 'SassNull' is not a subtype of type 'FutureOr<SassNull0>?'",
    status: 3
  },
  result: null
}

This error is being thrown by this code. Note that:

  • dart2js thinks there are two distinct types: SassNull and SassNull0.
  • result is SassNull returns true, despite the fact that SassNull in that context should refer to the same type as the return type declaration.
  • This only happens for the SassNull type. There are various other names (such as SassNumber and SassString) that actually do apply to multiple types, but they don't exhibit this behavior since one of the types extends the other.
  • This only happens in Sass's asynchronous compilation mode, likely because the type check is being performed by the completer generated by the async/await transformation.

This is a fairly severe issue for us, since it means that we essentially can't run asynchronous JS compilations in development mode which makes it difficult to catch real type errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.customer-dart-sasstype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dart2js

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions