Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ab66a38

Browse files
fishythefishcommit-bot@chromium.org
authored andcommitted
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 dart-lang/sdk#36562. Change-Id: I00d1e693bb3f1268ac100a76c9bec8fcc612b182 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99101 Commit-Queue: Mayank Patke <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]>
1 parent 585debb commit ab66a38

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,14 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
21932193
// With JS semantics, an integer is also a double.
21942194
return true;
21952195
}
2196+
2197+
if (constantType == typeEnvironment.doubleType &&
2198+
type == typeEnvironment.intType) {
2199+
double value = (constant as DoubleConstant).value;
2200+
if (value.isFinite && value == value.truncateToDouble()) {
2201+
return true;
2202+
}
2203+
}
21962204
}
21972205
return typeEnvironment.isSubtypeOf(constantType, type);
21982206
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
const int x = 0;
6+
7+
const List<int> l = const [
8+
1,
9+
-x,
10+
];
11+
12+
main() => print(l);

0 commit comments

Comments
 (0)