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

Unified Diff: pkg/compiler/lib/src/resolution/constructors.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/resolution/constructors.dart
diff --git a/pkg/compiler/lib/src/resolution/constructors.dart b/pkg/compiler/lib/src/resolution/constructors.dart
index 7a4dbc68af735d296d314058213cbcc0a99162b1..a7845793ab7ac18fe8ed3f51ee49ab9301defa41 100644
--- a/pkg/compiler/lib/src/resolution/constructors.dart
+++ b/pkg/compiler/lib/src/resolution/constructors.dart
@@ -424,11 +424,24 @@ class InitializerResolver {
constructorInvocation = resolveImplicitSuperConstructorSend();
}
if (isConst && isValidAsConstant) {
- constructor.constantConstructor = new GenerativeConstantConstructor(
- constructor.enclosingClass.thisType,
- defaultValues,
- fieldInitializers,
- constructorInvocation);
+ constructor.enclosingClass.forEachInstanceField((_, FieldElement field) {
+ if (!fieldInitializers.containsKey(field)) {
+ visitor.resolution.ensureResolved(field);
+ // TODO(johnniwinther): Report error if `field.constant` is `null`.
+ if (field.constant != null) {
+ fieldInitializers[field] = field.constant;
+ } else {
+ isValidAsConstant = false;
+ }
+ }
+ });
+ if (isValidAsConstant) {
+ constructor.constantConstructor = new GenerativeConstantConstructor(
+ constructor.enclosingClass.thisType,
+ defaultValues,
+ fieldInitializers,
+ constructorInvocation);
+ }
}
return null; // If there was no redirection always return null.
}

Powered by Google App Engine
This is Rietveld 408576698