dart-archive / polymer-dart

Polymer support for Dart
https://pub.dartlang.org/packages/polymer
BSD 3-Clause "New" or "Revised" License
181 stars 33 forks source link

Binding with double properties (subtle problem) #627

Closed dam0vm3nt closed 8 years ago

dam0vm3nt commented 8 years ago

Calling notifyPath on a property of type double will cause an error in checked mode if the number have 0 fractional part (for example "867.0"). This is caused by JS imperfect type handling. The new value will go through the JS proxy that will automatically cast a double with non fractional part to an int and then dart will complain about trying to assign an int to a double field.

jakemac53 commented 8 years ago

:(

jakemac53 commented 8 years ago

I guess the only real solution would be to use num instead of double. This is really a general js interop issue, and doing reflection on the dart field before each assignment (to convert int to double) isn't really worth it.

Maybe adding in a warning for numeric properties other than int and num is reasonable.

sigmundch commented 8 years ago

.. doing reflection on the dart field before each assignment (to convert int to double) isn't really worth it.

Also, this conversion is not possible in dart2js: dart2js is restricted by how numbers are represented in JS. It's one of those corner cases where the VM and dart2js differ. For example, this Dart program will print true in dart2js, but false in the vm/dartium:

main() => print(3.0 is int);

num is probably the best you can do.

jakemac53 commented 8 years ago

I am going to close this as "working as intended" for now, but opened https://github.com/dart-lang/polymer-dart/issues/628

dam0vm3nt commented 8 years ago

The only (don't know if actually feasible with current reflectable) other solution I had in mind is to check the property type before notifying and forcing a toDouble in case... but it is actually not worth and too costly. #628 it's just ok for me too. Thanks.