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

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

Issue 845183004: Use synthetic elements to recover from errors in signatures.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r42768. Created 5 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/pkg/compiler/lib/src/resolution/resolution.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 part of resolution; 5 part of resolution;
6 6
7 /** 7 /**
8 * [SignatureResolver] resolves function signatures. 8 * [SignatureResolver] resolves function signatures.
9 */ 9 */
10 class SignatureResolver extends MappingVisitor<FormalElementX> { 10 class SignatureResolver extends MappingVisitor<FormalElementX> {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } else if (link.head.asSend() != null && 111 } else if (link.head.asSend() != null &&
112 link.head.asSend().selector.asFunctionExpression() != null) { 112 link.head.asSend().selector.asFunctionExpression() != null) {
113 // Inline function typed initializing formal or 113 // Inline function typed initializing formal or
114 // parameter with default value, like `C(int this.f(String s))` or 114 // parameter with default value, like `C(int this.f(String s))` or
115 // `void m([int f(String s) = null])`. 115 // `void m([int f(String s) = null])`.
116 computeFunctionType(link.head.asSend().selector.asFunctionExpression()); 116 computeFunctionType(link.head.asSend().selector.asFunctionExpression());
117 } else { 117 } else {
118 assert(invariant(currentDefinitions, 118 assert(invariant(currentDefinitions,
119 link.head.asIdentifier() != null || link.head.asSend() != null)); 119 link.head.asIdentifier() != null || link.head.asSend() != null));
120 if (fieldElement != null) { 120 if (fieldElement != null) {
121 element.typeCache = fieldElement.computeType(compiler); 121 element.typeCache = fieldElement.computeType(compiler);
ahe 2015/01/12 10:25:32 I added ErroneousFieldElementX.computeType to prev
122 } else { 122 } else {
123 element.typeCache = const DynamicType(); 123 element.typeCache = const DynamicType();
124 } 124 }
125 } 125 }
126 } 126 }
127 } 127 }
128 128
129 Element visitIdentifier(Identifier node) { 129 Element visitIdentifier(Identifier node) {
130 return createParameter(node, null); 130 return createParameter(node, null);
131 } 131 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 parameter = new FormalElementX( 165 parameter = new FormalElementX(
166 ElementKind.PARAMETER, enclosingElement, currentDefinitions, name); 166 ElementKind.PARAMETER, enclosingElement, currentDefinitions, name);
167 } 167 }
168 computeParameterType(parameter); 168 computeParameterType(parameter);
169 return parameter; 169 return parameter;
170 } 170 }
171 171
172 InitializingFormalElementX createFieldParameter(Send node, 172 InitializingFormalElementX createFieldParameter(Send node,
173 Expression initializer) { 173 Expression initializer) {
174 InitializingFormalElementX element; 174 InitializingFormalElementX element;
175 if (node.receiver.asIdentifier() == null || 175 Identifier receiver = node.receiver.asIdentifier();
176 !node.receiver.asIdentifier().isThis()) { 176 if (receiver == null || !receiver.isThis()) {
177 error(node, MessageKind.INVALID_PARAMETER); 177 error(node, MessageKind.INVALID_PARAMETER);
178 } else if (!identical(enclosingElement.kind, 178 return new ErroneousInitializingFormalElementX(
179 ElementKind.GENERATIVE_CONSTRUCTOR)) { 179 getParameterName(node), enclosingElement);
180 error(node, MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED);
181 // TODO(ahe): Don't throw, recover from error.
182 throw new CompilerCancelledException(null);
183 } else { 180 } else {
181 if (!enclosingElement.isGenerativeConstructor) {
182 error(node, MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED);
183 return new ErroneousInitializingFormalElementX(
184 getParameterName(node), enclosingElement);
185 }
184 Identifier name = getParameterName(node); 186 Identifier name = getParameterName(node);
185 validateName(name); 187 validateName(name);
186 Element fieldElement = 188 Element fieldElement =
187 enclosingElement.enclosingClass.lookupLocalMember(name.source); 189 enclosingElement.enclosingClass.lookupLocalMember(name.source);
188 if (fieldElement == null || 190 if (fieldElement == null ||
189 !identical(fieldElement.kind, ElementKind.FIELD)) { 191 !identical(fieldElement.kind, ElementKind.FIELD)) {
190 error(node, MessageKind.NOT_A_FIELD, {'fieldName': name}); 192 error(node, MessageKind.NOT_A_FIELD, {'fieldName': name});
191 // TODO(ahe): Don't throw, recover from error. 193 fieldElement = new ErroneousFieldElementX(
192 throw new CompilerCancelledException(null); 194 name, enclosingElement.enclosingClass);
193 } else if (!fieldElement.isInstanceMember) { 195 } else if (!fieldElement.isInstanceMember) {
194 error(node, MessageKind.NOT_INSTANCE_FIELD, {'fieldName': name}); 196 error(node, MessageKind.NOT_INSTANCE_FIELD, {'fieldName': name});
197 fieldElement = new ErroneousFieldElementX(
198 name, enclosingElement.enclosingClass);
195 } 199 }
196 element = new InitializingFormalElementX(enclosingElement, 200 element = new InitializingFormalElementX(enclosingElement,
197 currentDefinitions, name, initializer, fieldElement); 201 currentDefinitions, name, initializer, fieldElement);
198 computeParameterType(element, fieldElement); 202 computeParameterType(element, fieldElement);
199 } 203 }
200 return element; 204 return element;
201 } 205 }
202 206
203 /// A [SendSet] node is an optional parameter with a default value. 207 /// A [SendSet] node is an optional parameter with a default value.
204 Element visitSendSet(SendSet node) { 208 Element visitSendSet(SendSet node) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 378
375 DartType resolveReturnType(TypeAnnotation annotation) { 379 DartType resolveReturnType(TypeAnnotation annotation) {
376 if (annotation == null) return const DynamicType(); 380 if (annotation == null) return const DynamicType();
377 DartType result = resolver.resolveTypeAnnotation(annotation); 381 DartType result = resolver.resolveTypeAnnotation(annotation);
378 if (result == null) { 382 if (result == null) {
379 return const DynamicType(); 383 return const DynamicType();
380 } 384 }
381 return result; 385 return result;
382 } 386 }
383 } 387 }
OLDNEW
« no previous file with comments | « dart/pkg/compiler/lib/src/resolution/resolution.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698