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

Generic has wrong runtimeType if compiled to JS #24666

Closed
MikeMitterer opened this Issue Oct 21, 2015 · 1 comment

Comments

Projects
None yet
3 participants
@MikeMitterer

MikeMitterer commented Oct 21, 2015

How you can reproduce it:
Take this sample: http://samples.material-design-lite.pub/mdld_repeat_data-table/index.html
Open the console and click on EVGA... (price 110.12)
You can see the result of this line:

_logger.fine("Input-Value: '$val' (${val.runtimeType}) -> '${_value}' (${_value.runtimeType})");

I use OvservableProperty for setting the value (https://goo.gl/ZoVsMe)
I take the untyped input value, check against the generic runtimeType and convert if necessary. In the above sample the input value (double) 110.12 should stay the same. This works fine with the DartVM but fails if compiled to JS.
The JS-Version returns int as runtimeType for a generic defined as double.

Here is the definition (main.dart where I define final ObservableProperty<double> total: https://goo.gl/c4QTtE
If you tick the checkbox then this line sets the value https://goo.gl/plF0sX and produces the log output.

Output in Dartium/Chromium:
screenshot-1877

An here is Chrome:
screenshot-1878

@sigmundch

This comment has been minimized.

Member

sigmundch commented Oct 21, 2015

This is one of those few cases where the vm and dart2js differ by design. Dart2js' runtime types of numbers is derived from the numeric representation we get in JavaScript, where 0.0 and 0 are equivalent.

In your example, this means that an initial value of 0.0 will set initial type as int, not double.

Here is a small example that also illustrates the situation:

main() {
  var x = 1.0;
  print(x.runtimeType);
  print(x.toDouble().runtimeType);
  print(x.toInt().runtimeType);
}

This will print double double int in the VM, but int int int in dart2js.

Making as a duplicate of #1533

@sigmundch sigmundch closed this Oct 21, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment