Add more JS subtyping semantics to CFE constant evaluator.

If we're targeting a JS backend, `isSubtype` considers every int to be a
double. We need to additionally allow any integer-valued double to be an
int. This mainly allows us to handle signed zeroes correctly.

Fixes https://github.com/dart-lang/sdk/issues/36562.

Change-Id: I00d1e693bb3f1268ac100a76c9bec8fcc612b182
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99101
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
diff --git a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
index d35150d..e6c5630 100644
--- a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
@@ -2191,6 +2191,14 @@
         // With JS semantics, an integer is also a double.
         return true;
       }
+
+      if (constantType == typeEnvironment.doubleType &&
+          type == typeEnvironment.intType) {
+        double value = (constant as DoubleConstant).value;
+        if (value.isFinite && value == value.truncateToDouble()) {
+          return true;
+        }
+      }
     }
     return typeEnvironment.isSubtypeOf(constantType, type);
   }
diff --git a/tests/compiler/dart2js_extra/issue36562_test.dart b/tests/compiler/dart2js_extra/issue36562_test.dart
new file mode 100644
index 0000000..cd43f16
--- /dev/null
+++ b/tests/compiler/dart2js_extra/issue36562_test.dart
@@ -0,0 +1,12 @@
+// Copyright (c) 2019, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+const int x = 0;
+
+const List<int> l = const [
+  1,
+  -x,
+];
+
+main() => print(l);