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

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

Issue 1363993004: Report info messages together with their error, warning, or hint. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment. Created 5 years, 2 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
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.constructors; 5 library dart2js.resolution.constructors;
6 import '../compiler.dart' show 6 import '../compiler.dart' show
7 Compiler; 7 Compiler;
8 import '../constants/constructors.dart' show 8 import '../constants/constructors.dart' show
9 GenerativeConstantConstructor, 9 GenerativeConstantConstructor,
10 RedirectingGenerativeConstantConstructor; 10 RedirectingGenerativeConstantConstructor;
11 import '../constants/expressions.dart'; 11 import '../constants/expressions.dart';
12 import '../dart_types.dart'; 12 import '../dart_types.dart';
13 import '../diagnostics/diagnostic_listener.dart' show
14 DiagnosticListener,
15 DiagnosticMessage;
13 import '../diagnostics/invariant.dart' show 16 import '../diagnostics/invariant.dart' show
14 invariant; 17 invariant;
15 import '../diagnostics/messages.dart' show 18 import '../diagnostics/messages.dart' show
16 MessageKind; 19 MessageKind;
17 import '../diagnostics/spannable.dart' show 20 import '../diagnostics/spannable.dart' show
18 Spannable; 21 Spannable;
19 import '../elements/elements.dart'; 22 import '../elements/elements.dart';
20 import '../elements/modelx.dart' show 23 import '../elements/modelx.dart' show
21 ConstructorElementX, 24 ConstructorElementX,
22 ErroneousConstructorElementX, 25 ErroneousConstructorElementX,
(...skipping 29 matching lines...) Expand all
52 Link<Node> initializers; 55 Link<Node> initializers;
53 bool hasSuper = false; 56 bool hasSuper = false;
54 bool isValidAsConstant = true; 57 bool isValidAsConstant = true;
55 58
56 bool get isConst => constructor.isConst; 59 bool get isConst => constructor.isConst;
57 60
58 InitializerResolver(this.visitor, this.constructor, this.functionNode); 61 InitializerResolver(this.visitor, this.constructor, this.functionNode);
59 62
60 ResolutionRegistry get registry => visitor.registry; 63 ResolutionRegistry get registry => visitor.registry;
61 64
62 error(Node node, MessageKind kind, [arguments = const {}]) { 65 DiagnosticListener get listener => visitor.compiler;
63 visitor.error(node, kind, arguments);
64 }
65
66 warning(Node node, MessageKind kind, [arguments = const {}]) {
67 visitor.warning(node, kind, arguments);
68 }
69 66
70 bool isFieldInitializer(SendSet node) { 67 bool isFieldInitializer(SendSet node) {
71 if (node.selector.asIdentifier() == null) return false; 68 if (node.selector.asIdentifier() == null) return false;
72 if (node.receiver == null) return true; 69 if (node.receiver == null) return true;
73 if (node.receiver.asIdentifier() == null) return false; 70 if (node.receiver.asIdentifier() == null) return false;
74 return node.receiver.asIdentifier().isThis(); 71 return node.receiver.asIdentifier().isThis();
75 } 72 }
76 73
77 reportDuplicateInitializerError(Element field, Node init, Node existing) { 74 reportDuplicateInitializerError(Element field, Node init, Node existing) {
78 visitor.compiler.reportError( 75 listener.reportError(
79 init, 76 listener.createMessage(
80 MessageKind.DUPLICATE_INITIALIZER, {'fieldName': field.name}); 77 init,
81 visitor.compiler.reportInfo( 78 MessageKind.DUPLICATE_INITIALIZER,
82 existing, 79 {'fieldName': field.name}),
83 MessageKind.ALREADY_INITIALIZED, {'fieldName': field.name}); 80 <DiagnosticMessage>[
81 listener.createMessage(
82 existing,
83 MessageKind.ALREADY_INITIALIZED,
84 {'fieldName': field.name}),
85 ]);
84 isValidAsConstant = false; 86 isValidAsConstant = false;
85 } 87 }
86 88
87 void checkForDuplicateInitializers(FieldElementX field, Node init) { 89 void checkForDuplicateInitializers(FieldElementX field, Node init) {
88 // [field] can be null if it could not be resolved. 90 // [field] can be null if it could not be resolved.
89 if (field == null) return; 91 if (field == null) return;
90 if (initialized.containsKey(field)) { 92 if (initialized.containsKey(field)) {
91 reportDuplicateInitializerError(field, init, initialized[field]); 93 reportDuplicateInitializerError(field, init, initialized[field]);
92 } else if (field.isFinal) { 94 } else if (field.isFinal) {
93 field.parseNode(visitor.compiler); 95 field.parseNode(visitor.compiler);
94 Expression initializer = field.initializer; 96 Expression initializer = field.initializer;
95 if (initializer != null) { 97 if (initializer != null) {
96 reportDuplicateInitializerError(field, init, initializer); 98 reportDuplicateInitializerError(field, init, initializer);
97 } 99 }
98 } 100 }
99 initialized[field] = init; 101 initialized[field] = init;
100 } 102 }
101 103
102 void resolveFieldInitializer(SendSet init) { 104 void resolveFieldInitializer(SendSet init) {
103 // init is of the form [this.]field = value. 105 // init is of the form [this.]field = value.
104 final Node selector = init.selector; 106 final Node selector = init.selector;
105 final String name = selector.asIdentifier().source; 107 final String name = selector.asIdentifier().source;
106 // Lookup target field. 108 // Lookup target field.
107 Element target; 109 Element target;
108 FieldElement field; 110 FieldElement field;
109 if (isFieldInitializer(init)) { 111 if (isFieldInitializer(init)) {
110 target = constructor.enclosingClass.lookupLocalMember(name); 112 target = constructor.enclosingClass.lookupLocalMember(name);
111 if (target == null) { 113 if (target == null) {
112 error(selector, MessageKind.CANNOT_RESOLVE, {'name': name}); 114 listener.reportErrorMessage(
115 selector, MessageKind.CANNOT_RESOLVE, {'name': name});
113 target = new ErroneousFieldElementX( 116 target = new ErroneousFieldElementX(
114 selector.asIdentifier(), constructor.enclosingClass); 117 selector.asIdentifier(), constructor.enclosingClass);
115 } else if (target.kind != ElementKind.FIELD) { 118 } else if (target.kind != ElementKind.FIELD) {
116 error(selector, MessageKind.NOT_A_FIELD, {'fieldName': name}); 119 listener.reportErrorMessage(
120 selector, MessageKind.NOT_A_FIELD, {'fieldName': name});
117 target = new ErroneousFieldElementX( 121 target = new ErroneousFieldElementX(
118 selector.asIdentifier(), constructor.enclosingClass); 122 selector.asIdentifier(), constructor.enclosingClass);
119 } else if (!target.isInstanceMember) { 123 } else if (!target.isInstanceMember) {
120 error(selector, MessageKind.INIT_STATIC_FIELD, {'fieldName': name}); 124 listener.reportErrorMessage(
125 selector, MessageKind.INIT_STATIC_FIELD, {'fieldName': name});
121 } else { 126 } else {
122 field = target; 127 field = target;
123 } 128 }
124 } else { 129 } else {
125 error(init, MessageKind.INVALID_RECEIVER_IN_INITIALIZER); 130 listener.reportErrorMessage(
131 init, MessageKind.INVALID_RECEIVER_IN_INITIALIZER);
126 } 132 }
127 registry.useElement(init, target); 133 registry.useElement(init, target);
128 registry.registerStaticUse(target); 134 registry.registerStaticUse(target);
129 checkForDuplicateInitializers(target, init); 135 checkForDuplicateInitializers(target, init);
130 // Resolve initializing value. 136 // Resolve initializing value.
131 ResolutionResult result = visitor.visitInStaticContext( 137 ResolutionResult result = visitor.visitInStaticContext(
132 init.arguments.head, 138 init.arguments.head,
133 inConstantInitializer: isConst); 139 inConstantInitializer: isConst);
134 if (isConst) { 140 if (isConst) {
135 if (result.isConstant && field != null) { 141 if (result.isConstant && field != null) {
136 // TODO(johnniwinther): Report error if `result.constant` is `null`. 142 // TODO(johnniwinther): Report error if `result.constant` is `null`.
137 fieldInitializers[field] = result.constant; 143 fieldInitializers[field] = result.constant;
138 } else { 144 } else {
139 isValidAsConstant = false; 145 isValidAsConstant = false;
140 } 146 }
141 } 147 }
142 } 148 }
143 149
144 InterfaceType getSuperOrThisLookupTarget(Node diagnosticNode, 150 InterfaceType getSuperOrThisLookupTarget(Node diagnosticNode,
145 {bool isSuperCall}) { 151 {bool isSuperCall}) {
146 if (isSuperCall) { 152 if (isSuperCall) {
147 // Calculate correct lookup target and constructor name. 153 // Calculate correct lookup target and constructor name.
148 if (identical(constructor.enclosingClass, visitor.compiler.objectClass)) { 154 if (identical(constructor.enclosingClass, visitor.compiler.objectClass)) {
149 error(diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); 155 listener.reportErrorMessage(
156 diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT);
150 isValidAsConstant = false; 157 isValidAsConstant = false;
151 } else { 158 } else {
152 return constructor.enclosingClass.supertype; 159 return constructor.enclosingClass.supertype;
153 } 160 }
154 } 161 }
155 return constructor.enclosingClass.thisType; 162 return constructor.enclosingClass.thisType;
156 } 163 }
157 164
158 ResolutionResult resolveSuperOrThisForSend(Send call) { 165 ResolutionResult resolveSuperOrThisForSend(Send call) {
159 // Resolve the selector and the arguments. 166 // Resolve the selector and the arguments.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 String className, 257 String className,
251 Selector constructorSelector) { 258 Selector constructorSelector) {
252 if (lookedupConstructor == null || 259 if (lookedupConstructor == null ||
253 !lookedupConstructor.isGenerativeConstructor) { 260 !lookedupConstructor.isGenerativeConstructor) {
254 String fullConstructorName = Elements.constructorNameForDiagnostics( 261 String fullConstructorName = Elements.constructorNameForDiagnostics(
255 className, 262 className,
256 constructorSelector.name); 263 constructorSelector.name);
257 MessageKind kind = isImplicitSuperCall 264 MessageKind kind = isImplicitSuperCall
258 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT 265 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT
259 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; 266 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR;
260 visitor.compiler.reportError( 267 listener.reportErrorMessage(
261 diagnosticNode, kind, {'constructorName': fullConstructorName}); 268 diagnosticNode, kind, {'constructorName': fullConstructorName});
262 isValidAsConstant = false; 269 isValidAsConstant = false;
263 } else { 270 } else {
264 lookedupConstructor.computeType(visitor.compiler); 271 lookedupConstructor.computeType(visitor.compiler);
265 if (!call.signatureApplies(lookedupConstructor.functionSignature)) { 272 if (!call.signatureApplies(lookedupConstructor.functionSignature)) {
266 MessageKind kind = isImplicitSuperCall 273 MessageKind kind = isImplicitSuperCall
267 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT 274 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT
268 : MessageKind.NO_MATCHING_CONSTRUCTOR; 275 : MessageKind.NO_MATCHING_CONSTRUCTOR;
269 visitor.compiler.reportError(diagnosticNode, kind); 276 listener.reportErrorMessage(diagnosticNode, kind);
270 isValidAsConstant = false; 277 isValidAsConstant = false;
271 } else if (constructor.isConst 278 } else if (constructor.isConst
272 && !lookedupConstructor.isConst) { 279 && !lookedupConstructor.isConst) {
273 MessageKind kind = isImplicitSuperCall 280 MessageKind kind = isImplicitSuperCall
274 ? MessageKind.CONST_CALLS_NON_CONST_FOR_IMPLICIT 281 ? MessageKind.CONST_CALLS_NON_CONST_FOR_IMPLICIT
275 : MessageKind.CONST_CALLS_NON_CONST; 282 : MessageKind.CONST_CALLS_NON_CONST;
276 visitor.compiler.reportError(diagnosticNode, kind); 283 listener.reportErrorMessage(diagnosticNode, kind);
277 isValidAsConstant = false; 284 isValidAsConstant = false;
278 } 285 }
279 } 286 }
280 } 287 }
281 288
282 /** 289 /**
283 * Resolve all initializers of this constructor. In the case of a redirecting 290 * Resolve all initializers of this constructor. In the case of a redirecting
284 * constructor, the resolved constructor's function element is returned. 291 * constructor, the resolved constructor's function element is returned.
285 */ 292 */
286 ConstructorElement resolveInitializers() { 293 ConstructorElement resolveInitializers() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 initializers = functionNode.initializers.nodes; 343 initializers = functionNode.initializers.nodes;
337 } 344 }
338 bool resolvedSuper = false; 345 bool resolvedSuper = false;
339 for (Link<Node> link = initializers; !link.isEmpty; link = link.tail) { 346 for (Link<Node> link = initializers; !link.isEmpty; link = link.tail) {
340 if (link.head.asSendSet() != null) { 347 if (link.head.asSendSet() != null) {
341 final SendSet init = link.head.asSendSet(); 348 final SendSet init = link.head.asSendSet();
342 resolveFieldInitializer(init); 349 resolveFieldInitializer(init);
343 } else if (link.head.asSend() != null) { 350 } else if (link.head.asSend() != null) {
344 final Send call = link.head.asSend(); 351 final Send call = link.head.asSend();
345 if (call.argumentsNode == null) { 352 if (call.argumentsNode == null) {
346 error(link.head, MessageKind.INVALID_INITIALIZER); 353 listener.reportErrorMessage(
354 link.head, MessageKind.INVALID_INITIALIZER);
347 continue; 355 continue;
348 } 356 }
349 if (Initializers.isSuperConstructorCall(call)) { 357 if (Initializers.isSuperConstructorCall(call)) {
350 if (resolvedSuper) { 358 if (resolvedSuper) {
351 error(call, MessageKind.DUPLICATE_SUPER_INITIALIZER); 359 listener.reportErrorMessage(
360 call, MessageKind.DUPLICATE_SUPER_INITIALIZER);
352 } 361 }
353 ResolutionResult result = resolveSuperOrThisForSend(call); 362 ResolutionResult result = resolveSuperOrThisForSend(call);
354 if (isConst) { 363 if (isConst) {
355 if (result.isConstant) { 364 if (result.isConstant) {
356 constructorInvocation = result.constant; 365 constructorInvocation = result.constant;
357 } else { 366 } else {
358 isValidAsConstant = false; 367 isValidAsConstant = false;
359 } 368 }
360 } 369 }
361 resolvedSuper = true; 370 resolvedSuper = true;
362 } else if (Initializers.isConstructorRedirect(call)) { 371 } else if (Initializers.isConstructorRedirect(call)) {
363 // Check that there is no body (Language specification 7.5.1). If the 372 // Check that there is no body (Language specification 7.5.1). If the
364 // constructor is also const, we already reported an error in 373 // constructor is also const, we already reported an error in
365 // [resolveMethodElement]. 374 // [resolveMethodElement].
366 if (functionNode.hasBody() && !constructor.isConst) { 375 if (functionNode.hasBody() && !constructor.isConst) {
367 error(functionNode, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY); 376 listener.reportErrorMessage(
377 functionNode, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY);
368 } 378 }
369 // Check that there are no other initializers. 379 // Check that there are no other initializers.
370 if (!initializers.tail.isEmpty) { 380 if (!initializers.tail.isEmpty) {
371 error(call, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER); 381 listener.reportErrorMessage(
382 call, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER);
372 } else { 383 } else {
373 constructor.isRedirectingGenerative = true; 384 constructor.isRedirectingGenerative = true;
374 } 385 }
375 // Check that there are no field initializing parameters. 386 // Check that there are no field initializing parameters.
376 FunctionSignature signature = constructor.functionSignature; 387 FunctionSignature signature = constructor.functionSignature;
377 signature.forEachParameter((ParameterElement parameter) { 388 signature.forEachParameter((ParameterElement parameter) {
378 if (parameter.isInitializingFormal) { 389 if (parameter.isInitializingFormal) {
379 Node node = parameter.node; 390 Node node = parameter.node;
380 error(node, MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED); 391 listener.reportErrorMessage(
392 node, MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED);
381 isValidAsConstant = false; 393 isValidAsConstant = false;
382 } 394 }
383 }); 395 });
384 ResolutionResult result = resolveSuperOrThisForSend(call); 396 ResolutionResult result = resolveSuperOrThisForSend(call);
385 if (isConst) { 397 if (isConst) {
386 if (result.isConstant) { 398 if (result.isConstant) {
387 constructorInvocation = result.constant; 399 constructorInvocation = result.constant;
388 } else { 400 } else {
389 isValidAsConstant = false; 401 isValidAsConstant = false;
390 } 402 }
391 if (isConst && isValidAsConstant) { 403 if (isConst && isValidAsConstant) {
392 constructor.constantConstructor = 404 constructor.constantConstructor =
393 new RedirectingGenerativeConstantConstructor( 405 new RedirectingGenerativeConstantConstructor(
394 defaultValues, 406 defaultValues,
395 constructorInvocation); 407 constructorInvocation);
396 } 408 }
397 } 409 }
398 return result.element; 410 return result.element;
399 } else { 411 } else {
400 visitor.error(call, MessageKind.CONSTRUCTOR_CALL_EXPECTED); 412 listener.reportErrorMessage(
413 call, MessageKind.CONSTRUCTOR_CALL_EXPECTED);
401 return null; 414 return null;
402 } 415 }
403 } else { 416 } else {
404 error(link.head, MessageKind.INVALID_INITIALIZER); 417 listener.reportErrorMessage(
418 link.head, MessageKind.INVALID_INITIALIZER);
405 } 419 }
406 } 420 }
407 if (!resolvedSuper) { 421 if (!resolvedSuper) {
408 constructorInvocation = resolveImplicitSuperConstructorSend(); 422 constructorInvocation = resolveImplicitSuperConstructorSend();
409 } 423 }
410 if (isConst && isValidAsConstant) { 424 if (isConst && isValidAsConstant) {
411 constructor.constantConstructor = new GenerativeConstantConstructor( 425 constructor.constantConstructor = new GenerativeConstantConstructor(
412 constructor.enclosingClass.thisType, 426 constructor.enclosingClass.thisType,
413 defaultValues, 427 defaultValues,
414 fieldInitializers, 428 fieldInitializers,
(...skipping 26 matching lines...) Expand all
441 MessageKind kind, 455 MessageKind kind,
442 Map arguments, 456 Map arguments,
443 {bool isError: false, 457 {bool isError: false,
444 bool missingConstructor: false}) { 458 bool missingConstructor: false}) {
445 if (missingConstructor) { 459 if (missingConstructor) {
446 registry.registerThrowNoSuchMethod(); 460 registry.registerThrowNoSuchMethod();
447 } else { 461 } else {
448 registry.registerThrowRuntimeError(); 462 registry.registerThrowRuntimeError();
449 } 463 }
450 if (isError || inConstContext) { 464 if (isError || inConstContext) {
451 compiler.reportError(diagnosticNode, kind, arguments); 465 compiler.reportErrorMessage(
466 diagnosticNode, kind, arguments);
452 } else { 467 } else {
453 compiler.reportWarning(diagnosticNode, kind, arguments); 468 compiler.reportWarningMessage(
469 diagnosticNode, kind, arguments);
454 } 470 }
455 ErroneousElement error = new ErroneousConstructorElementX( 471 ErroneousElement error = new ErroneousConstructorElementX(
456 kind, arguments, name, enclosing); 472 kind, arguments, name, enclosing);
457 if (type == null) { 473 if (type == null) {
458 type = new MalformedType(error, null); 474 type = new MalformedType(error, null);
459 } 475 }
460 return new ConstructorResult(resultKind, error, type); 476 return new ConstructorResult(resultKind, error, type);
461 } 477 }
462 478
463 ConstructorResult resolveConstructor( 479 ConstructorResult resolveConstructor(
464 InterfaceType type, 480 InterfaceType type,
465 Node diagnosticNode, 481 Node diagnosticNode,
466 String constructorName) { 482 String constructorName) {
467 ClassElement cls = type.element; 483 ClassElement cls = type.element;
468 cls.ensureResolved(compiler); 484 cls.ensureResolved(compiler);
469 ConstructorElement constructor = findConstructor( 485 ConstructorElement constructor = findConstructor(
470 resolver.enclosingElement.library, cls, constructorName); 486 resolver.enclosingElement.library, cls, constructorName);
471 if (constructor == null) { 487 if (constructor == null) {
472 String fullConstructorName = 488 String fullConstructorName =
473 Elements.constructorNameForDiagnostics(cls.name, constructorName); 489 Elements.constructorNameForDiagnostics(cls.name, constructorName);
474 return reportAndCreateErroneousConstructorElement( 490 return reportAndCreateErroneousConstructorElement(
475 diagnosticNode, 491 diagnosticNode,
476 ConstructorResultKind.UNRESOLVED_CONSTRUCTOR, type, 492 ConstructorResultKind.UNRESOLVED_CONSTRUCTOR, type,
477 cls, constructorName, 493 cls, constructorName,
478 MessageKind.CANNOT_FIND_CONSTRUCTOR, 494 MessageKind.CANNOT_FIND_CONSTRUCTOR,
479 {'constructorName': fullConstructorName}, 495 {'constructorName': fullConstructorName},
480 missingConstructor: true); 496 missingConstructor: true);
481 } else if (inConstContext && !constructor.isConst) { 497 } else if (inConstContext && !constructor.isConst) {
482 compiler.reportError( 498 compiler.reportErrorMessage(
483 diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); 499 diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST);
484 return new ConstructorResult( 500 return new ConstructorResult(
485 ConstructorResultKind.NON_CONSTANT, constructor, type); 501 ConstructorResultKind.NON_CONSTANT, constructor, type);
486 } else { 502 } else {
487 if (constructor.isGenerativeConstructor) { 503 if (constructor.isGenerativeConstructor) {
488 if (cls.isAbstract) { 504 if (cls.isAbstract) {
489 compiler.reportWarning( 505 compiler.reportWarningMessage(
490 diagnosticNode, MessageKind.ABSTRACT_CLASS_INSTANTIATION); 506 diagnosticNode, MessageKind.ABSTRACT_CLASS_INSTANTIATION);
491 registry.registerAbstractClassInstantiation(); 507 registry.registerAbstractClassInstantiation();
492 return new ConstructorResult( 508 return new ConstructorResult(
493 ConstructorResultKind.ABSTRACT, constructor, type); 509 ConstructorResultKind.ABSTRACT, constructor, type);
494 } else { 510 } else {
495 return new ConstructorResult( 511 return new ConstructorResult(
496 ConstructorResultKind.GENERATIVE, constructor, type); 512 ConstructorResultKind.GENERATIVE, constructor, type);
497 } 513 }
498 } else { 514 } else {
499 assert(invariant(diagnosticNode, constructor.isFactoryConstructor, 515 assert(invariant(diagnosticNode, constructor.isFactoryConstructor,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 assert(invariant(node.receiver, receiver != null, 579 assert(invariant(node.receiver, receiver != null,
564 message: 'No result returned for $node.receiver.')); 580 message: 'No result returned for $node.receiver.'));
565 if (receiver.kind != null) { 581 if (receiver.kind != null) {
566 assert(invariant(node, receiver.element.isErroneous, 582 assert(invariant(node, receiver.element.isErroneous,
567 message: "Unexpected prefix result: $receiver.")); 583 message: "Unexpected prefix result: $receiver."));
568 // We have already found an error. 584 // We have already found an error.
569 return receiver; 585 return receiver;
570 } 586 }
571 587
572 Identifier name = node.selector.asIdentifier(); 588 Identifier name = node.selector.asIdentifier();
573 if (name == null) internalError(node.selector, 'unexpected node'); 589 if (name == null) {
590 compiler.internalError(node.selector, 'unexpected node');
591 }
574 592
575 if (receiver.type != null) { 593 if (receiver.type != null) {
576 if (receiver.type.isInterfaceType) { 594 if (receiver.type.isInterfaceType) {
577 return resolveConstructor(receiver.type, name, name.source); 595 return resolveConstructor(receiver.type, name, name.source);
578 } else { 596 } else {
579 // TODO(johnniwinther): Update the message for the different types. 597 // TODO(johnniwinther): Update the message for the different types.
580 return reportAndCreateErroneousConstructorElement( 598 return reportAndCreateErroneousConstructorElement(
581 name, 599 name,
582 ConstructorResultKind.INVALID_TYPE, null, 600 ConstructorResultKind.INVALID_TYPE, null,
583 resolver.enclosingElement, name.source, 601 resolver.enclosingElement, name.source,
584 MessageKind.NOT_A_TYPE, {'node': name}); 602 MessageKind.NOT_A_TYPE, {'node': name});
585 } 603 }
586 } else if (receiver.element.isPrefix) { 604 } else if (receiver.element.isPrefix) {
587 PrefixElement prefix = receiver.element; 605 PrefixElement prefix = receiver.element;
588 Element member = prefix.lookupLocalMember(name.source); 606 Element member = prefix.lookupLocalMember(name.source);
589 return constructorResultForElement(node, name.source, member); 607 return constructorResultForElement(node, name.source, member);
590 } else { 608 } else {
591 return internalError(node.receiver, 'unexpected receiver $receiver'); 609 return compiler.internalError(
610 node.receiver, 'unexpected receiver $receiver');
592 } 611 }
593 } 612 }
594 613
595 ConstructorResult visitIdentifier(Identifier node) { 614 ConstructorResult visitIdentifier(Identifier node) {
596 String name = node.source; 615 String name = node.source;
597 Element element = resolver.reportLookupErrorIfAny( 616 Element element = resolver.reportLookupErrorIfAny(
598 lookupInScope(compiler, node, resolver.scope, name), node, name); 617 lookupInScope(compiler, node, resolver.scope, name), node, name);
599 registry.useElement(node, element); 618 registry.useElement(node, element);
600 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1. 619 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1.
601 return constructorResultForElement(node, name, element); 620 return constructorResultForElement(node, name, element);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 resolver.enclosingElement, name, 692 resolver.enclosingElement, name,
674 MessageKind.CANNOT_INSTANTIATE_TYPEDEF, {'typedefName': name}); 693 MessageKind.CANNOT_INSTANTIATE_TYPEDEF, {'typedefName': name});
675 } else if (type.isTypeVariable) { 694 } else if (type.isTypeVariable) {
676 return reportAndCreateErroneousConstructorElement( 695 return reportAndCreateErroneousConstructorElement(
677 node, 696 node,
678 ConstructorResultKind.INVALID_TYPE, type, 697 ConstructorResultKind.INVALID_TYPE, type,
679 resolver.enclosingElement, name, 698 resolver.enclosingElement, name,
680 MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, 699 MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE,
681 {'typeVariableName': name}); 700 {'typeVariableName': name});
682 } 701 }
683 internalError(node, "Unexpected constructor type $type"); 702 return compiler.internalError(node, "Unexpected constructor type $type");
684 return null;
685 } 703 }
686 704
687 } 705 }
688 706
689 enum ConstructorResultKind { 707 enum ConstructorResultKind {
690 GENERATIVE, 708 GENERATIVE,
691 FACTORY, 709 FACTORY,
692 ABSTRACT, 710 ABSTRACT,
693 INVALID_TYPE, 711 INVALID_TYPE,
694 UNRESOLVED_CONSTRUCTOR, 712 UNRESOLVED_CONSTRUCTOR,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 // constructors. 757 // constructors.
740 return null; 758 return null;
741 } 759 }
742 // TODO(johnniwinther): Use [Name] for lookup. 760 // TODO(johnniwinther): Use [Name] for lookup.
743 ConstructorElement constructor = cls.lookupConstructor(constructorName); 761 ConstructorElement constructor = cls.lookupConstructor(constructorName);
744 if (constructor != null) { 762 if (constructor != null) {
745 constructor = constructor.declaration; 763 constructor = constructor.declaration;
746 } 764 }
747 return constructor; 765 return constructor;
748 } 766 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/class_members.dart ('k') | pkg/compiler/lib/src/resolution/members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698