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

Unified Diff: pkg/kernel/lib/transformations/closure/rewriter.dart

Issue 2971293002: Fix closure conversion in field and local initializers. (Closed)
Patch Set: Created 3 years, 5 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/kernel/lib/transformations/closure/rewriter.dart
diff --git a/pkg/kernel/lib/transformations/closure/rewriter.dart b/pkg/kernel/lib/transformations/closure/rewriter.dart
index 255398cb061bccc3658478b2c2066477a5a732ae..41b1a408eff10157c6065c6bc082d2d296c3946d 100644
--- a/pkg/kernel/lib/transformations/closure/rewriter.dart
+++ b/pkg/kernel/lib/transformations/closure/rewriter.dart
@@ -100,9 +100,10 @@ abstract class InitializerRewriter extends AstRewriter {
@override
void insertContextDeclaration(Expression accessParent) {
_createDeclaration();
+ var oldParent = initializingExpression.parent;
Let binding = new Let(contextDeclaration, initializingExpression);
+ binding.parent = oldParent;
setInitializerExpression(binding);
- initializingExpression.parent = binding;
}
@override
@@ -124,23 +125,19 @@ class FieldInitializerRewriter extends InitializerRewriter {
}
void setInitializerExpression(Expression expression) {
- assert(initializingExpression.parent is FieldInitializer);
- FieldInitializer parent = initializingExpression.parent;
- parent.value = expression;
- expression.parent = parent;
+ expression.parent.value = expression;
}
}
class LocalInitializerRewriter extends InitializerRewriter {
LocalInitializerRewriter(Expression initializingExpression)
: super(initializingExpression) {
- assert(initializingExpression.parent is LocalInitializer);
+ // The initializer is up two levels because the variable declaration node is
+ // in between.
+ assert(initializingExpression.parent.parent is LocalInitializer);
}
void setInitializerExpression(Expression expression) {
- assert(initializingExpression.parent is LocalInitializer);
- LocalInitializer parent = initializingExpression.parent;
- parent.variable.initializer = expression;
- expression.parent = parent;
+ expression.parent.initializer = expression;
}
}

Powered by Google App Engine
This is Rietveld 408576698