sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[dart2js] NaN accepted as valid index

Open creativecreatorormaybenot opened this issue 4 years ago • 12 comments

Bug

For some reason, this snippet of code works on every platform (including dart2js), but it just breaks in DDC:

OpenSimplex2S(42);

The error thrown is:

Error: RangeError (index): Value not in range: NaN
    at Object.throw_ [as throw] (http://localhost:63481/dart_sdk.js:5061:11)
    at Object._checkValidIndex (http://localhost:63481/dart_sdk.js:31695:17)
    at Int16Array.[dartx._get] (http://localhost:63481/dart_sdk.js:30652:26)
    at new open_simplex_2s.OpenSimplex2S.new (http://localhost:63481/packages/open_simplex_2/src/open_simplex_2s.dart.lib.js:3207:42)

I was able to trace it down to this line:

https://github.com/creativecreatorormaybenot/funvas/blob/f5db955bf109c2eb9ff1cb5ccfea3bf8629ef6af/open_simplex_2/lib/src/open_simplex_2s.dart#L46

Now, assuming that r in this case is NaN, I would think that:

seed = 42 * int.parse('6364136223846793005') + int.parse('1442695040888963407');

Causes a NaN value. What confuses me about this (if my assumption is true) is that this works in dart2js.

Reproduction

The steps to reproduce are stable:

  1. Depend on open_simplex_2: 0.1.0+1.
  2. Call the constructor of one of the two classes:
import 'package:open_simplex_2/open_simplex_2.dart';

void main() {
  OpenSimplex2S(42);
}
  1. Run this on DDC → RangeError is thrown.
  2. Run this on any other platform (e.g. compiling using dart2js) → works like a charm.