Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Unified Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 2104843002: Handle fields with initializers in constant constructors. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix invariants. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/elements/modelx.dart
diff --git a/pkg/compiler/lib/src/elements/modelx.dart b/pkg/compiler/lib/src/elements/modelx.dart
index e2588fc24fb1a419e139ce03e57f2399ec836445..bb331d96027f82fb2e26338ecc1b4130fdc95288 100644
--- a/pkg/compiler/lib/src/elements/modelx.dart
+++ b/pkg/compiler/lib/src/elements/modelx.dart
@@ -1425,11 +1425,22 @@ abstract class ConstantVariableMixin implements VariableElement {
// constant for a variable already known to be erroneous.
return;
}
- assert(invariant(this, constantCache == null || constantCache == value,
- message: "Constant has already been computed for $this. "
- "Existing constant: "
- "${constantCache != null ? constantCache.toStructuredText() : ''}, "
- "New constant: ${value != null ? value.toStructuredText() : ''}."));
+ if (constantCache != null && constantCache != value) {
+ // Allow setting the constant as erroneous. Constants computed during
+ // resolution are locally valid but might be effectively erroneous. For
+ // instance `a ? true : false` where a is `const a = m()`. Since `a` is
+ // declared to be constant, the conditional is assumed valid, but when
+ // computing the value we see that it isn't.
+ // TODO(johnniwinther): Remove this exception when all constant
+ // expressions are computed during resolution.
+ assert(invariant(
+ this, value == null || value.kind == ConstantExpressionKind.ERRONEOUS,
+ message: "Constant has already been computed for $this. "
+ "Existing constant: "
+ "${constantCache != null ? constantCache.toStructuredText() : ''}"
+ ", New constant: "
+ "${value != null ? value.toStructuredText() : ''}."));
+ }
constantCache = value;
}
}
« no previous file with comments | « pkg/compiler/lib/src/constants/constant_constructors.dart ('k') | pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698