| OLD | NEW |
| 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 operator[](Node node); | 8 Element operator[](Node node); |
| 9 Selector getSelector(Send send); | 9 Selector getSelector(Send send); |
| 10 DartType getType(Node node); | 10 DartType getType(Node node); |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 } | 688 } |
| 689 } | 689 } |
| 690 | 690 |
| 691 void checkUserDefinableOperator(Element member) { | 691 void checkUserDefinableOperator(Element member) { |
| 692 FunctionElement function = member.asFunctionElement(); | 692 FunctionElement function = member.asFunctionElement(); |
| 693 if (function == null) return; | 693 if (function == null) return; |
| 694 String value = member.name.stringValue; | 694 String value = member.name.stringValue; |
| 695 if (value == null) return; | 695 if (value == null) return; |
| 696 if (!(isUserDefinableOperator(value) || identical(value, 'unary-'))) return; | 696 if (!(isUserDefinableOperator(value) || identical(value, 'unary-'))) return; |
| 697 | 697 |
| 698 bool isMinus = false; | |
| 699 int requiredParameterCount; | 698 int requiredParameterCount; |
| 700 MessageKind messageKind; | 699 MessageKind messageKind; |
| 701 FunctionSignature signature = function.computeSignature(compiler); | 700 FunctionSignature signature = function.computeSignature(compiler); |
| 702 if (identical(value, 'unary-')) { | 701 if (identical(value, 'unary-')) { |
| 703 isMinus = true; | |
| 704 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY; | 702 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY; |
| 705 requiredParameterCount = 0; | 703 requiredParameterCount = 0; |
| 706 } else if (isMinusOperator(value)) { | 704 } else if (isMinusOperator(value)) { |
| 707 isMinus = true; | |
| 708 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY; | 705 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY; |
| 709 requiredParameterCount = 1; | 706 requiredParameterCount = 1; |
| 710 } else if (isUnaryOperator(value)) { | 707 } else if (isUnaryOperator(value)) { |
| 711 messageKind = MessageKind.UNARY_OPERATOR_BAD_ARITY; | 708 messageKind = MessageKind.UNARY_OPERATOR_BAD_ARITY; |
| 712 requiredParameterCount = 0; | 709 requiredParameterCount = 0; |
| 713 } else if (isBinaryOperator(value)) { | 710 } else if (isBinaryOperator(value)) { |
| 714 messageKind = MessageKind.BINARY_OPERATOR_BAD_ARITY; | 711 messageKind = MessageKind.BINARY_OPERATOR_BAD_ARITY; |
| 715 requiredParameterCount = 1; | 712 requiredParameterCount = 1; |
| 716 } else if (isTernaryOperator(value)) { | 713 } else if (isTernaryOperator(value)) { |
| 717 messageKind = MessageKind.TERNARY_OPERATOR_BAD_ARITY; | 714 messageKind = MessageKind.TERNARY_OPERATOR_BAD_ARITY; |
| 718 requiredParameterCount = 2; | 715 requiredParameterCount = 2; |
| 719 } else { | 716 } else { |
| 720 compiler.internalErrorOnElement(function, | 717 compiler.internalErrorOnElement(function, |
| 721 'Unexpected user defined operator $value'); | 718 'Unexpected user defined operator $value'); |
| 722 } | 719 } |
| 723 checkArity(function, requiredParameterCount, messageKind, isMinus); | 720 checkArity(function, requiredParameterCount, messageKind); |
| 724 } | 721 } |
| 725 | 722 |
| 726 void checkArity(FunctionElement function, | 723 void checkArity(FunctionElement function, |
| 727 int requiredParameterCount, MessageKind messageKind, | 724 int requiredParameterCount, MessageKind messageKind) { |
| 728 bool isMinus) { | |
| 729 FunctionExpression node = function.parseNode(compiler); | 725 FunctionExpression node = function.parseNode(compiler); |
| 730 FunctionSignature signature = function.computeSignature(compiler); | 726 FunctionSignature signature = function.computeSignature(compiler); |
| 731 if (signature.requiredParameterCount != requiredParameterCount) { | 727 if (signature.requiredParameterCount != requiredParameterCount) { |
| 732 Node errorNode = node; | 728 Node errorNode = node; |
| 733 if (node.parameters != null) { | 729 if (node.parameters != null) { |
| 734 if (isMinus || | 730 if (signature.requiredParameterCount < requiredParameterCount) { |
| 735 signature.requiredParameterCount < requiredParameterCount) { | |
| 736 // If there are too few parameters, point to the whole parameter list. | |
| 737 // For instance | |
| 738 // | |
| 739 // int operator +() {} | |
| 740 // ^^ | |
| 741 // | |
| 742 // int operator []=(value) {} | |
| 743 // ^^^^^^^ | |
| 744 // | |
| 745 // For operator -, always point the whole parameter list, like | |
| 746 // | |
| 747 // int operator -(a, b) {} | |
| 748 // ^^^^^^ | |
| 749 // | |
| 750 // instead of | |
| 751 // | |
| 752 // int operator -(a, b) {} | |
| 753 // ^ | |
| 754 // | |
| 755 // since the correction might not be to remove 'b' but instead to | |
| 756 // remove 'a, b'. | |
| 757 errorNode = node.parameters; | 731 errorNode = node.parameters; |
| 758 } else { | 732 } else { |
| 759 errorNode = node.parameters.nodes.skip(requiredParameterCount).head; | 733 errorNode = node.parameters.nodes.skip(requiredParameterCount).head; |
| 760 } | 734 } |
| 761 } | 735 } |
| 762 compiler.reportMessage( | 736 compiler.reportMessage( |
| 763 compiler.spanFromSpannable(errorNode), | 737 compiler.spanFromSpannable(errorNode), |
| 764 messageKind.error([function.name]), | 738 messageKind.error([function.name]), |
| 765 Diagnostic.ERROR); | 739 Diagnostic.ERROR); |
| 766 } | 740 } |
| (...skipping 2866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3633 return e; | 3607 return e; |
| 3634 } | 3608 } |
| 3635 | 3609 |
| 3636 /// Assumed to be called by [resolveRedirectingFactory]. | 3610 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3637 Element visitReturn(Return node) { | 3611 Element visitReturn(Return node) { |
| 3638 Node expression = node.expression; | 3612 Node expression = node.expression; |
| 3639 return finishConstructorReference(visit(expression), | 3613 return finishConstructorReference(visit(expression), |
| 3640 expression, expression); | 3614 expression, expression); |
| 3641 } | 3615 } |
| 3642 } | 3616 } |
| OLD | NEW |