| Index: pkg/compiler/lib/src/closure.dart
|
| diff --git a/pkg/compiler/lib/src/closure.dart b/pkg/compiler/lib/src/closure.dart
|
| index da13773cc34c247e567a2aa38ac694ee64c1fe2d..d630beb80c19a9adbd6f9445a92c29553e6a255f 100644
|
| --- a/pkg/compiler/lib/src/closure.dart
|
| +++ b/pkg/compiler/lib/src/closure.dart
|
| @@ -906,6 +906,7 @@ class ClosureTranslator extends Visitor {
|
| }
|
|
|
| visitFor(For node) {
|
| + List<LocalVariableElement> boxedLoopVariables = <LocalVariableElement>[];
|
| inNewScope(node, () {
|
| // First visit initializer and update so we can easily check if a loop
|
| // variable was captured in one of these subexpressions.
|
| @@ -929,24 +930,27 @@ class ClosureTranslator extends Visitor {
|
| // condition or body are indeed flagged as mutated.
|
| if (node.conditionStatement != null) visit(node.conditionStatement);
|
| if (node.body != null) visit(node.body);
|
| +
|
| + // See if we have declared loop variables that need to be boxed.
|
| + if (node.initializer == null) return;
|
| + VariableDefinitions definitions =
|
| + node.initializer.asVariableDefinitions();
|
| + if (definitions == null) return;
|
| + for (Link<Node> link = definitions.definitions.nodes;
|
| + !link.isEmpty;
|
| + link = link.tail) {
|
| + Node definition = link.head;
|
| + LocalVariableElement element = elements[definition];
|
| + // Non-mutated variables should not be boxed. The mutatedVariables set
|
| + // gets cleared when 'inNewScope' returns, so check it here.
|
| + if (isCapturedVariable(element) && mutatedVariables.contains(element)) {
|
| + boxedLoopVariables.add(element);
|
| + }
|
| + }
|
| });
|
| - // See if we have declared loop variables that need to be boxed.
|
| - if (node.initializer == null) return;
|
| - VariableDefinitions definitions = node.initializer.asVariableDefinitions();
|
| - if (definitions == null) return;
|
| ClosureScope scopeData = closureData.capturingScopes[node];
|
| if (scopeData == null) return;
|
| - List<LocalVariableElement> result = <LocalVariableElement>[];
|
| - for (Link<Node> link = definitions.definitions.nodes;
|
| - !link.isEmpty;
|
| - link = link.tail) {
|
| - Node definition = link.head;
|
| - LocalVariableElement element = elements[definition];
|
| - if (isCapturedVariable(element)) {
|
| - result.add(element);
|
| - }
|
| - }
|
| - scopeData.boxedLoopVariables = result;
|
| + scopeData.boxedLoopVariables = boxedLoopVariables;
|
| }
|
|
|
| /** Returns a non-unique name for the given closure element. */
|
|
|