mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 15:31:32 +00:00
workaround for #33885, constant evaluation in Analyzer sometimes fails
Change-Id: I3cc641caab94210d38a893f849b4590dba77f47c Reviewed-on: https://dart-review.googlesource.com/66225 Commit-Queue: Jenny Messerly <jmesserly@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
parent
0212fbad89
commit
78ce706775
|
@ -2997,11 +2997,25 @@ class CodeGenerator extends Object
|
|||
return element.jsVariable;
|
||||
}
|
||||
|
||||
// Directly emit constants.
|
||||
// As an optimization, directly emit simple constants.
|
||||
// (This is not required for correctness.)
|
||||
if (element is VariableElement && element.isStatic && element.isConst) {
|
||||
var val = element.computeConstantValue() as DartObjectImpl;
|
||||
var result = val.isBoolNumStringOrNull ? _emitDartObject(val) : null;
|
||||
if (result != null) return result;
|
||||
var value = element.computeConstantValue() as DartObjectImpl;
|
||||
// TODO(jmesserly): value should always be non-null unless the program has
|
||||
// errors. However constants seem to be missing in some cases, see:
|
||||
// https://github.com/dart-lang/sdk/issues/33885
|
||||
//
|
||||
// This may be an Analyzer bug. This workaround prevents a compiler crash
|
||||
// until we can track down the root cause (or migrate to CFE+Kernel).
|
||||
//
|
||||
// If the constant is not a primitive (or we fail to evaluate it), then
|
||||
// we can fall through and emit a reference to it at runtime.
|
||||
//
|
||||
// TODO(jmesserly): avoid inlining strings depending on their length.
|
||||
if (value != null && value.isBoolNumStringOrNull) {
|
||||
var result = _emitDartObject(value);
|
||||
if (result != null) return result;
|
||||
}
|
||||
}
|
||||
|
||||
// type literal
|
||||
|
|
Loading…
Reference in a new issue