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

Unified Diff: pkg/compiler/lib/src/js_backend/backend.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/js_backend/backend.dart
diff --git a/pkg/compiler/lib/src/js_backend/backend.dart b/pkg/compiler/lib/src/js_backend/backend.dart
index 7489914a3e70deba3fcc2a864191e4b5d8aba83d..cbae71286b2011c603c27cd6c4d8b2aa968c2841 100644
--- a/pkg/compiler/lib/src/js_backend/backend.dart
+++ b/pkg/compiler/lib/src/js_backend/backend.dart
@@ -1527,17 +1527,24 @@ class JavaScriptBackend extends Backend {
ConstantExpression constant = variableElement.constant;
if (constant != null) {
ConstantValue initialValue = constants.getConstantValue(constant);
- assert(invariant(variableElement, initialValue != null,
- message: "Constant expression without value: "
- "${constant.toStructuredText()}."));
- registerCompileTimeConstant(initialValue, work.registry);
- addCompileTimeConstantForEmission(initialValue);
- // We don't need to generate code for static or top-level
- // variables. For instance variables, we may need to generate
- // the checked setter.
- if (Elements.isStaticOrTopLevel(element)) {
- return impactTransformer
- .transformCodegenImpact(work.registry.worldImpact);
+ if (initialValue != null) {
+ registerCompileTimeConstant(initialValue, work.registry);
+ addCompileTimeConstantForEmission(initialValue);
+ // We don't need to generate code for static or top-level
+ // variables. For instance variables, we may need to generate
+ // the checked setter.
+ if (Elements.isStaticOrTopLevel(element)) {
+ return impactTransformer
+ .transformCodegenImpact(work.registry.worldImpact);
+ }
+ } else {
+ assert(invariant(
+ variableElement,
+ variableElement.isInstanceMember ||
+ constant.isImplicit ||
+ constant.isPotential,
+ message: "Constant expression without value: "
+ "${constant.toStructuredText()}."));
}
} else {
// If the constant-handler was not able to produce a result we have to
« no previous file with comments | « pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart ('k') | pkg/compiler/lib/src/resolution/constructors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698