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

Side by Side Diff: pkg/compiler/lib/src/resolution/variables.dart

Issue 1503063002: Handle const loop variable. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.resolution.variables; 5 library dart2js.resolution.variables;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../compiler.dart' show 8 import '../compiler.dart' show
9 Compiler; 9 Compiler;
10 import '../elements/modelx.dart' show 10 import '../elements/modelx.dart' show
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 return identifier; 54 return identifier;
55 } 55 }
56 56
57 Identifier visitIdentifier(Identifier node) { 57 Identifier visitIdentifier(Identifier node) {
58 // The variable is initialized to null. 58 // The variable is initialized to null.
59 // TODO(johnniwinther): Register a feature instead. 59 // TODO(johnniwinther): Register a feature instead.
60 registry.registerTypeUse( 60 registry.registerTypeUse(
61 new TypeUse.instantiation(compiler.coreTypes.nullType)); 61 new TypeUse.instantiation(compiler.coreTypes.nullType));
62 if (definitions.modifiers.isConst) { 62 if (definitions.modifiers.isConst) {
63 reporter.reportErrorMessage( 63 if (resolver.inLoopVariable) {
64 node, MessageKind.CONST_WITHOUT_INITIALIZER); 64 reporter.reportErrorMessage(
65 node, MessageKind.CONST_LOOP_VARIABLE);
66 } else {
67 reporter.reportErrorMessage(
68 node, MessageKind.CONST_WITHOUT_INITIALIZER);
69 }
65 } 70 }
66 if (definitions.modifiers.isFinal && 71 if (definitions.modifiers.isFinal &&
67 !resolver.allowFinalWithoutInitializer) { 72 !resolver.inLoopVariable) {
68 reporter.reportErrorMessage( 73 reporter.reportErrorMessage(
69 node, MessageKind.FINAL_WITHOUT_INITIALIZER); 74 node, MessageKind.FINAL_WITHOUT_INITIALIZER);
70 } 75 }
71 return node; 76 return node;
72 } 77 }
73 78
74 visitNodeList(NodeList node) { 79 visitNodeList(NodeList node) {
75 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) { 80 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) {
76 Identifier name = visit(link.head); 81 Identifier name = visit(link.head);
77 LocalVariableElementX element = new LocalVariableElementX( 82 LocalVariableElementX element = new LocalVariableElementX(
78 name.source, resolver.enclosingElement, 83 name.source, resolver.enclosingElement,
79 variables, name.token); 84 variables, name.token);
80 resolver.defineLocalVariable(link.head, element); 85 resolver.defineLocalVariable(link.head, element);
81 resolver.addToScope(element); 86 resolver.addToScope(element);
82 if (definitions.modifiers.isConst) { 87 if (definitions.modifiers.isConst) {
83 compiler.enqueuer.resolution.addDeferredAction(element, () { 88 compiler.enqueuer.resolution.addDeferredAction(element, () {
84 element.constant = 89 element.constant =
85 compiler.resolver.constantCompiler.compileConstant(element); 90 compiler.resolver.constantCompiler.compileConstant(element);
86 }); 91 });
87 } 92 }
88 } 93 }
89 } 94 }
90 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698