Skip to content

Runtime type error in dart pad (compiled by dart2js) but not on VM #49588

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

Closed
annagrin opened this issue Aug 3, 2022 · 2 comments
Closed

Runtime type error in dart pad (compiled by dart2js) but not on VM #49588

annagrin opened this issue Aug 3, 2022 · 2 comments
Assignees
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@annagrin
Copy link
Contributor

annagrin commented Aug 3, 2022

The following code runs successfully on VM and Chrome (if compiled with DDC), but fails on dart pad with a runtime error (or in chrome when compiled with dart2js):

// @dart = 2.17
import 'dart:async';

void main() {
  final controller = StreamController<Map<String, Object?>>();
  controller.stream.listen(print);
  addFoo(controller.sink);
  print('done');
}

void addFoo(StreamSink<Map<String, Object?>> sink)   {
  if (sink is StreamSink<Map<String, Object>>) throw 'bad sink'; // Removing this line makes the code work
  sink.add({'foo': 'bar'});
}

Expected

_StreamSinkWrapper<Map<String, Object?>>
done
{foo: bar}

Actual

_StreamSinkWrapper<Map<String, Object?>>
Uncaught TypeError: t1.add$1 is not a functionError: TypeError: t1.add$1 is not a function
@fishythefish fishythefish added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. labels Aug 3, 2022
@fishythefish
Copy link
Member

fishythefish commented Aug 3, 2022

Reduced example with no imports:

class Foo<T> {
  void blah() => print("Foo");
}

void main() {
  final foo = Foo<int?>();
  if (foo is Foo<int>) throw 'bad foo';
  foo.blah();
}

@fishythefish fishythefish self-assigned this Aug 8, 2022
@fishythefish
Copy link
Member

The static type computation in dart2js doesn't take nullability into account. I'm working on correcting this.

copybara-service bot pushed a commit that referenced this issue Mar 17, 2023
Bug: #49588
Change-Id: If19b956642ff55ca6d54e7b9df21cbc516d05d93
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253710
Reviewed-by: Stephen Adams <[email protected]>
Commit-Queue: Mayank Patke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

2 participants