Analyzer constant evaluation special-cases identical(int, double)
.
#60647
Labels
analyzer-constants
area-dart-model
For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.
model-const-eval
Implementation of constant evaluation in analyzer/cfe
The analyzer constant evaluation has a special case for
identical(c1, c2)
when one is a double and the other anint
, in particular:I think it should stop doing that.
The behavior is that if one value is an
int
and the other adouble
, the analyzer decides that it doesn't know if they are identical or not. (Even if they weren't even equal.)That can have downstream consequences, where code that tries to have separate branches for JS-numbers and native numbers will have both branches analyzed, even if one of them will always fail.
As a degenerate example:
The real issue occurred in testing, where I needed a bigger delta than
1
for some tests when running with JS precision,so I had
var offset = jsNumbers ? 1024 : 1;
. That ends up being an "unknown integer constant" in the analyzer, not either actual value I wanted.Then I tested constant evaluation of
const Duration(hours: max, microseconds: offset)
, and it did not trigger an assert that checked for overflow (because an "unkown bool" value of an assert does not report an error), but it did fail in a later branch guarded by the same condition as the assert, because it hit something that was intended to throw during non-constant evaluation, and be guarded by the assert in constant evaluation.Which means I got spurious errors in an error test when run with the analyzer.
I think the analyzer should not special case here. It runs constant evaluation with either JS or native semantics, and it's not like it doesn't know which. (It's native.)
Trying to not admit that just pushes people to do other tests, like:
which compares only integers, still distinguishes when those integers are actually doubles, and doesn't pretend that it doesn't know in the analyzer.
(That's what I switched to in my test, and is putting into
package:expect/variations.dart
instead ofidentical(1, 1.0)
.)The text was updated successfully, but these errors were encountered: