Skip to content
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

Dart2+JS Interop: Discrepancies in support/cast errors #33129

Closed
matanlurey opened this issue May 15, 2018 · 11 comments
Closed

Dart2+JS Interop: Discrepancies in support/cast errors #33129

matanlurey opened this issue May 15, 2018 · 11 comments
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue P2 A bug or feature request we're likely to work on web-dart2js web-dev-compiler web-js-interop Issues that impact all js interop

Comments

@matanlurey
Copy link
Contributor

(I consider this a HIGH/P1 issue due to production bugs hit by internal teams)

Both internal and external users have been suffering a bit due to the lack of (a) clear documentation of intended use of package:js and (b) slightly different runtime and compile-time errors and functionality. In one particular recent case, DDC worked fine, and our internal clients hit production bugs requiring multiple cherrypicks because Dart2JS threw exceptions (at runtime).

Here is a reproduction case of a production P0:
https://github.com/matanlurey/dart2_js_interop_casts

// lib/chart.dart
@JS()
library dart2_js_interop_casts.chart;

import 'package:js/js.dart';

@JS()
@anonymous
abstract class ChartData<T> {
  external factory ChartData({T data});
  T get data;
}

class TimeSeries {
  String get domain => 'Hello World';
}
// test/chart_test.dart
// Internally, this was production code, *not* a test.

@TestOn('browser')
import 'package:dart2_js_interop_casts/chart.dart';
import 'package:test/test.dart';

void main() {
  test('should fail in both DDC and Dart2JS', () {
    // Start with a ChartData<TimeSeries>.
    final explicitTypeChart = new ChartData<TimeSeries>(
      data: new TimeSeries(),
    );
    
    // Downcast to a ChartData<dynamic>.
    final ChartData<dynamic> downcastTypeChart = explicitTypeChart;

    // "As" cast back to ChartData<TimeSeries>.
    expect(
      () {
        downcastTypeChart as ChartData<TimeSeries>;  
      },
      returnsNormally,
    );
  });
}

With DDC:

$ pub run build_runner test

00:01 +1: All tests passed!

With Dart2JS:

$ pub run build_runner test --release

  Expected: return normally
    Actual: <Closure 'main__closure'>
     Which: threw CastErrorImplementation:<CastError: Instance of 'PlainJavaScriptObject': type 'PlainJavaScriptObject' is not a subtype of type 'ChartData<TimeSeries>'>

(I know there are some meta issues around generic types/JS interop already)

@matanlurey matanlurey added P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js web-js-interop Issues that impact all js interop web-dev-compiler labels May 15, 2018
@matanlurey
Copy link
Contributor Author

/cc @jmesserly @vsmenon @sigmundch as this hit an escalation internally.

@vsmenon
Copy link
Member

vsmenon commented May 15, 2018

@jacob314 @jmesserly @sigmundch @rakudrama - what do you all think is the right behavior here?

I believe we're effectively treating the generic as unreified / Dart-1 ish in DDC.

@jmesserly
Copy link

I added this to #32929

To my knowledge there is no spec for JS interop, nor errors for incorrect usage. DDC can go pretty far off the rails in some cases, and that's not even getting into DDC/dart2js differences.

@sigmundch
Copy link
Member

sigmundch commented May 15, 2018

@matanlurey - what version of dart2js was used here?

This seems to be the same as #32929 (I discovered the issue also running this in an internal app with a very similar error message, possibly the same). We landed a fix in dart2js in 54b8ebd which is avalable in -dev.52 onwards.

@matanlurey
Copy link
Contributor Author

matanlurey commented May 15, 2018 via email

@sigmundch
Copy link
Member

I'm a bit puzzled, "--preview-dart-2" is not enabled internally yet, let's chat offline when you have a chance to better understand what's happening here.

@matanlurey
Copy link
Contributor Author

Talked offline with @sigmundch, this occurs in Dart1-mode.

The ChartData class being manually reified, i.e. an explicit new ChartData<TimeSeries>, which does work in Dart1 (class type). I actually tried this with --preview-dart-2 and it works (no error). Does that change how we should proceed?

@sigmundch
Copy link
Member

My inclination is that yes: I hope we can skip fixing this in dart2js-dart1 mode and avoid the problem until projects switch to use dart2.

@matanlurey
Copy link
Contributor Author

Great. I'm happy to close this (though I think #32929 will cover "spec" issues and hopefully avoid more of these in the future).

@matanlurey
Copy link
Contributor Author

Lowering priority to P2. @sigmundch feel free to close if needed.

@matanlurey matanlurey added P2 A bug or feature request we're likely to work on and removed P1 A high priority bug; for example, a single project is unusable or has many test failures labels May 15, 2018
@sigmundch
Copy link
Member

Thanks @matanlurey, I'll close this as not-planned, but please do reopen or ping me if this becomes a pain point and we need to reevaluate.

@sigmundch sigmundch added the closed-not-planned Closed as we don't intend to take action on the reported issue label May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue P2 A bug or feature request we're likely to work on web-dart2js web-dev-compiler web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

4 participants