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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 346553002: Cleanup argument mismatch message. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 abstract class TreeElements { 7 abstract class TreeElements {
8 Element get currentElement; 8 Element get currentElement;
9 Setlet<Node> get superUses; 9 Setlet<Node> get superUses;
10 10
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 return processMetadata(); 291 return processMetadata();
292 } else if (element.isTypedef) { 292 } else if (element.isTypedef) {
293 TypedefElement typdef = element; 293 TypedefElement typdef = element;
294 return processMetadata(resolveTypedef(typdef)); 294 return processMetadata(resolveTypedef(typdef));
295 } 295 }
296 296
297 compiler.unimplemented(element, "resolve($element)"); 297 compiler.unimplemented(element, "resolve($element)");
298 }); 298 });
299 } 299 }
300 300
301 String constructorNameForDiagnostics(String className,
302 String constructorName) {
303 String classNameString = className;
304 String constructorNameString = constructorName;
305 return (constructorName == '')
306 ? classNameString
307 : "$classNameString.$constructorNameString";
308 }
309
310 void resolveRedirectingConstructor(InitializerResolver resolver, 301 void resolveRedirectingConstructor(InitializerResolver resolver,
311 Node node, 302 Node node,
312 FunctionElement constructor, 303 FunctionElement constructor,
313 FunctionElement redirection) { 304 FunctionElement redirection) {
314 assert(invariant(node, constructor.isImplementation, 305 assert(invariant(node, constructor.isImplementation,
315 message: 'Redirecting constructors must be resolved on implementation ' 306 message: 'Redirecting constructors must be resolved on implementation '
316 'elements.')); 307 'elements.'));
317 Setlet<FunctionElement> seen = new Setlet<FunctionElement>(); 308 Setlet<FunctionElement> seen = new Setlet<FunctionElement>();
318 seen.add(constructor); 309 seen.add(constructor);
319 while (redirection != null) { 310 while (redirection != null) {
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 void verifyThatConstructorMatchesCall( 1409 void verifyThatConstructorMatchesCall(
1419 FunctionElement caller, 1410 FunctionElement caller,
1420 FunctionElement lookedupConstructor, 1411 FunctionElement lookedupConstructor,
1421 Selector call, 1412 Selector call,
1422 bool isImplicitSuperCall, 1413 bool isImplicitSuperCall,
1423 Node diagnosticNode, 1414 Node diagnosticNode,
1424 String className, 1415 String className,
1425 Selector constructorSelector) { 1416 Selector constructorSelector) {
1426 if (lookedupConstructor == null 1417 if (lookedupConstructor == null
1427 || !lookedupConstructor.isGenerativeConstructor) { 1418 || !lookedupConstructor.isGenerativeConstructor) {
1428 var fullConstructorName = 1419 String fullConstructorName = Elements.constructorNameForDiagnostics(
1429 visitor.compiler.resolver.constructorNameForDiagnostics(
1430 className, 1420 className,
1431 constructorSelector.name); 1421 constructorSelector.name);
1432 MessageKind kind = isImplicitSuperCall 1422 MessageKind kind = isImplicitSuperCall
1433 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT 1423 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT
1434 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; 1424 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR;
1435 visitor.compiler.reportError( 1425 visitor.compiler.reportError(
1436 diagnosticNode, kind, {'constructorName': fullConstructorName}); 1426 diagnosticNode, kind, {'constructorName': fullConstructorName});
1437 } else { 1427 } else {
1438 if (!call.applies(lookedupConstructor, visitor.compiler)) { 1428 if (!call.applies(lookedupConstructor, visitor.compiler)) {
1439 MessageKind kind = isImplicitSuperCall 1429 MessageKind kind = isImplicitSuperCall
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
2688 // If we don't know what we're calling or if we are calling a getter, 2678 // If we don't know what we're calling or if we are calling a getter,
2689 // we need to register that fact that we may be calling a closure 2679 // we need to register that fact that we may be calling a closure
2690 // with the same arguments. 2680 // with the same arguments.
2691 Selector call = new Selector.callClosureFrom(selector); 2681 Selector call = new Selector.callClosureFrom(selector);
2692 registry.registerDynamicInvocation(call); 2682 registry.registerDynamicInvocation(call);
2693 } else if (target.impliesType) { 2683 } else if (target.impliesType) {
2694 // We call 'call()' on a Type instance returned from the reference to a 2684 // We call 'call()' on a Type instance returned from the reference to a
2695 // class or typedef literal. We do not need to register this call as a 2685 // class or typedef literal. We do not need to register this call as a
2696 // dynamic invocation, because we statically know what the target is. 2686 // dynamic invocation, because we statically know what the target is.
2697 } else if (!selector.applies(target, compiler)) { 2687 } else if (!selector.applies(target, compiler)) {
2698 warnArgumentMismatch(node, target); 2688 registry.registerThrowNoSuchMethod();
2699 if (node.isSuperCall) { 2689 if (node.isSuperCall) {
2700 // Similar to what we do when we can't find super via selector 2690 // Similar to what we do when we can't find super via selector
2701 // in [resolveSend] above, we still need to register the invocation, 2691 // in [resolveSend] above, we still need to register the invocation,
2702 // because we might call [:super.noSuchMethod:] which calls 2692 // because we might call [:super.noSuchMethod:] which calls
2703 // [JSInvocationMirror._invokeOn]. 2693 // [JSInvocationMirror._invokeOn].
2704 registry.registerDynamicInvocation(selector); 2694 registry.registerDynamicInvocation(selector);
2705 registry.registerSuperNoSuchMethod(); 2695 registry.registerSuperNoSuchMethod();
2706 } 2696 }
2707 } 2697 }
2708 2698
(...skipping 13 matching lines...) Expand all
2722 } 2712 }
2723 2713
2724 registry.useElement(node, target); 2714 registry.useElement(node, target);
2725 registerSend(selector, target); 2715 registerSend(selector, target);
2726 if (node.isPropertyAccess && Elements.isStaticOrTopLevelFunction(target)) { 2716 if (node.isPropertyAccess && Elements.isStaticOrTopLevelFunction(target)) {
2727 registry.registerGetOfStaticFunction(target.declaration); 2717 registry.registerGetOfStaticFunction(target.declaration);
2728 } 2718 }
2729 return node.isPropertyAccess ? target : null; 2719 return node.isPropertyAccess ? target : null;
2730 } 2720 }
2731 2721
2732 void warnArgumentMismatch(Send node, Element target) {
2733 registry.registerThrowNoSuchMethod();
2734 // TODO(karlklose): we can be more precise about the reason of the
2735 // mismatch.
2736 warning(node.argumentsNode, MessageKind.INVALID_ARGUMENTS,
Johnni Winther 2014/06/18 14:32:01 We always warn in the typechecker so this caused d
2737 {'methodName': target.name});
2738 }
2739
2740 /// Callback for native enqueuer to parse a type. Returns [:null:] on error. 2722 /// Callback for native enqueuer to parse a type. Returns [:null:] on error.
2741 DartType resolveTypeFromString(Node node, String typeName) { 2723 DartType resolveTypeFromString(Node node, String typeName) {
2742 Element element = lookupInScope(compiler, node, 2724 Element element = lookupInScope(compiler, node,
2743 scope, typeName); 2725 scope, typeName);
2744 if (element == null) return null; 2726 if (element == null) return null;
2745 if (element is! ClassElement) return null; 2727 if (element is! ClassElement) return null;
2746 ClassElement cls = element; 2728 ClassElement cls = element;
2747 cls.ensureResolved(compiler); 2729 cls.ensureResolved(compiler);
2748 return cls.computeType(compiler); 2730 return cls.computeType(compiler);
2749 } 2731 }
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
3070 Node selector = node.send.selector; 3052 Node selector = node.send.selector;
3071 FunctionElement constructor = resolveConstructor(node); 3053 FunctionElement constructor = resolveConstructor(node);
3072 final bool isSymbolConstructor = constructor == compiler.symbolConstructor; 3054 final bool isSymbolConstructor = constructor == compiler.symbolConstructor;
3073 final bool isMirrorsUsedConstant = 3055 final bool isMirrorsUsedConstant =
3074 node.isConst && (constructor == compiler.mirrorsUsedConstructor); 3056 node.isConst && (constructor == compiler.mirrorsUsedConstructor);
3075 Selector callSelector = resolveSelector(node.send, constructor); 3057 Selector callSelector = resolveSelector(node.send, constructor);
3076 resolveArguments(node.send.argumentsNode); 3058 resolveArguments(node.send.argumentsNode);
3077 registry.useElement(node.send, constructor); 3059 registry.useElement(node.send, constructor);
3078 if (Elements.isUnresolved(constructor)) return constructor; 3060 if (Elements.isUnresolved(constructor)) return constructor;
3079 if (!callSelector.applies(constructor, compiler)) { 3061 if (!callSelector.applies(constructor, compiler)) {
3080 warnArgumentMismatch(node.send, constructor);
3081 registry.registerThrowNoSuchMethod(); 3062 registry.registerThrowNoSuchMethod();
3082 } 3063 }
3083 3064
3084 // [constructor] might be the implementation element 3065 // [constructor] might be the implementation element
3085 // and only declaration elements may be registered. 3066 // and only declaration elements may be registered.
3086 registry.registerStaticUse(constructor.declaration); 3067 registry.registerStaticUse(constructor.declaration);
3087 ClassElement cls = constructor.enclosingClass; 3068 ClassElement cls = constructor.enclosingClass;
3088 InterfaceType type = registry.getType(node); 3069 InterfaceType type = registry.getType(node);
3089 if (node.isConst && type.containsTypeVariables) { 3070 if (node.isConst && type.containsTypeVariables) {
3090 compiler.reportError(node.send.selector, 3071 compiler.reportError(node.send.selector,
(...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after
4554 resolver.enclosingElement.library); 4535 resolver.enclosingElement.library);
4555 } 4536 }
4556 4537
4557 FunctionElement resolveConstructor(ClassElement cls, 4538 FunctionElement resolveConstructor(ClassElement cls,
4558 Node diagnosticNode, 4539 Node diagnosticNode,
4559 String constructorName) { 4540 String constructorName) {
4560 cls.ensureResolved(compiler); 4541 cls.ensureResolved(compiler);
4561 Selector selector = createConstructorSelector(constructorName); 4542 Selector selector = createConstructorSelector(constructorName);
4562 Element result = cls.lookupConstructor(selector); 4543 Element result = cls.lookupConstructor(selector);
4563 if (result == null) { 4544 if (result == null) {
4564 String fullConstructorName = 4545 String fullConstructorName = Elements.constructorNameForDiagnostics(
4565 resolver.compiler.resolver.constructorNameForDiagnostics(
4566 cls.name, 4546 cls.name,
4567 constructorName); 4547 constructorName);
4568 return failOrReturnErroneousElement( 4548 return failOrReturnErroneousElement(
4569 cls, 4549 cls,
4570 diagnosticNode, 4550 diagnosticNode,
4571 fullConstructorName, 4551 fullConstructorName,
4572 MessageKind.CANNOT_FIND_CONSTRUCTOR, 4552 MessageKind.CANNOT_FIND_CONSTRUCTOR,
4573 {'constructorName': fullConstructorName}); 4553 {'constructorName': fullConstructorName});
4574 } else if (inConstContext && !result.isConst) { 4554 } else if (inConstContext && !result.isConst) {
4575 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); 4555 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
4709 TreeElements _treeElements; 4689 TreeElements _treeElements;
4710 4690
4711 bool get hasTreeElements => _treeElements != null; 4691 bool get hasTreeElements => _treeElements != null;
4712 4692
4713 TreeElements get treeElements { 4693 TreeElements get treeElements {
4714 assert(invariant(this, _treeElements !=null, 4694 assert(invariant(this, _treeElements !=null,
4715 message: "TreeElements have not been computed for $this.")); 4695 message: "TreeElements have not been computed for $this."));
4716 return _treeElements; 4696 return _treeElements;
4717 } 4697 }
4718 } 4698 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698