Index: pkg/kernel/lib/transformations/closure/converter.dart |
diff --git a/pkg/kernel/lib/transformations/closure/converter.dart b/pkg/kernel/lib/transformations/closure/converter.dart |
index e1865f7fd6d90a6c04a8e0dbeba37456490f612f..aef306c7106ec0d9513263b3144a1883801b9684 100644 |
--- a/pkg/kernel/lib/transformations/closure/converter.dart |
+++ b/pkg/kernel/lib/transformations/closure/converter.dart |
@@ -70,7 +70,13 @@ import 'context.dart' show Context, NoContext; |
import 'info.dart' show ClosureInfo; |
-import 'rewriter.dart' show AstRewriter, BlockRewriter, InitializerRewriter; |
+import 'rewriter.dart' |
+ show |
+ AstRewriter, |
+ BlockRewriter, |
+ InitializerRewriter, |
+ FieldInitializerRewriter, |
+ LocalInitializerRewriter; |
class ClosureConverter extends Transformer { |
final CoreTypes coreTypes; |
@@ -195,18 +201,47 @@ class ClosureConverter extends Transformer { |
context.extend(parameter, new VariableGet(parameter)); |
} |
+ static InitializerRewriter getRewriterForInitializer( |
+ Initializer initializer) { |
+ if (initializer is FieldInitializer) { |
+ return new FieldInitializerRewriter(initializer.value); |
+ } |
+ if (initializer is LocalInitializer) { |
+ return new LocalInitializerRewriter(initializer.variable.initializer); |
+ } |
+ throw "Trying to extract an initializer expression from " |
+ "${initializer.runtimeType}, but only FieldInitializer and " |
+ "LocalInitializer are supported."; |
+ } |
+ |
+ static Expression getInitializerExpression(Initializer initializer) { |
+ if (initializer is FieldInitializer) { |
+ return initializer.value; |
+ } |
+ if (initializer is LocalInitializer) { |
+ return initializer.variable.initializer; |
+ } |
+ throw "Trying to get initializing expressino from " |
+ "${initializer.runtimeType}, but only Field Initializer and " |
+ "LocalInitializer are supported."; |
+ } |
+ |
TreeNode visitConstructor(Constructor node) { |
assert(isEmptyContext); |
currentMember = node; |
// Transform initializers. |
for (Initializer initializer in node.initializers) { |
- if (initializer is FieldInitializer) { |
+ if (initializer is FieldInitializer || initializer is LocalInitializer) { |
// Create a rewriter and a context for the initializer expression. |
- rewriter = new InitializerRewriter(initializer.value); |
+ InitializerRewriter initializerRewriter = |
+ getRewriterForInitializer(initializer); |
+ rewriter = initializerRewriter; |
context = new NoContext(this); |
// Save the expression to visit it in the extended context, since the |
- // rewriter will modify `initializer.value`. |
- Expression initializerExpression = initializer.value; |
+ // rewriter will modify `initializer.value` (for [FieldInitializer]) or |
+ // `initializer.variable.initializer` (for [LocalInitializer]). |
+ Expression initializerExpression = |
+ getInitializerExpression(initializer); |
// Extend the context with all captured parameters of the constructor. |
// TODO(karlklose): add a fine-grained analysis of captured parameters. |
node.function.positionalParameters |
@@ -223,9 +258,11 @@ class ClosureConverter extends Transformer { |
parent.body = initializerExpression; |
} else if (parent is FieldInitializer) { |
parent.value = initializerExpression; |
+ } else if (parent is LocalInitializer) { |
+ parent.variable.initializer = initializerExpression; |
} else { |
throw "Found unexpected node '${node.runtimeType}, expected a 'Let' " |
- "or a 'FieldInitializer'."; |
+ ",a 'FieldInitializer', or a 'LocalInitializer'."; |
} |
} |
} |