Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| index 278e8009aefd1f5e80cbc64889ec83823f4221ee..9b2ee8849df68ed5de221cd93e85c6f00acc6d04 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| @@ -521,6 +521,7 @@ class ResolverTask extends CompilerTask { |
| } |
| checkAbstractField(member); |
| checkValidOverride(member, cls.lookupSuperMember(member.name)); |
| + checkUserDefinableOperator(member); |
| }); |
| } |
| @@ -589,6 +590,65 @@ class ResolverTask extends CompilerTask { |
| } |
| } |
| + void checkUserDefinableOperator(Element member) { |
| + FunctionElement function = member.asFunctionElement(); |
| + if (function == null) return; |
| + String value = member.name.stringValue; |
| + if (value == null) return; |
| + if (!(isUserDefinableOperator(value) || identical(value, 'unary-'))) return; |
| + |
| + FunctionSignature signature = function.computeSignature(compiler); |
| + if (identical(value, 'unary-')) { |
|
ahe
2013/01/09 10:17:52
Consider this approach:
int requiredParameterCoun
Johnni Winther
2013/01/09 13:00:47
Done.
|
| + if (signature.requiredParameterCount != 0) { |
|
ahe
2013/01/09 10:17:52
You should be able to assert this.
|
| + compiler.reportMessage( |
| + compiler.spanFromElement(function), |
| + MessageKind.MINUS_OPERATOR_BAD_ARITY.error(), |
| + Diagnostic.ERROR); |
| + } |
| + } else if (isMinusOperator(value)) { |
| + if (signature.requiredParameterCount != 1) { |
| + compiler.reportMessage( |
| + compiler.spanFromElement(function), |
| + MessageKind.MINUS_OPERATOR_BAD_ARITY.error(), |
| + Diagnostic.ERROR); |
| + } |
| + } else if (isUnaryOperator(value)) { |
| + if (signature.requiredParameterCount != 0) { |
| + compiler.reportMessage( |
| + compiler.spanFromElement(function), |
| + MessageKind.UNARY_OPERATOR_BAD_ARITY.error([function.name]), |
| + Diagnostic.ERROR); |
| + } |
| + } else if (isBinaryOperator(value)) { |
| + if (signature.requiredParameterCount != 1) { |
| + compiler.reportMessage( |
| + compiler.spanFromElement(function), |
| + MessageKind.BINARY_OPERATOR_BAD_ARITY.error([function.name]), |
| + Diagnostic.ERROR); |
| + } |
| + } else if (isTernaryOperator(value)) { |
| + if (signature.requiredParameterCount != 2) { |
| + compiler.reportMessage( |
| + compiler.spanFromElement(function), |
| + MessageKind.TERNARY_OPERATOR_BAD_ARITY.error([function.name]), |
| + Diagnostic.ERROR); |
| + } |
| + } |
|
ahe
2013/01/09 10:17:52
else {
// Internal error.
}
Johnni Winther
2013/01/09 13:00:47
Done.
|
| + if (signature.optionalParameterCount != 0) { |
| + if (signature.optionalParametersAreNamed) { |
| + compiler.reportMessage( |
| + compiler.spanFromElement(function), |
|
ahe
2013/01/09 10:17:52
There is a more accurate position for the optional
Johnni Winther
2013/01/09 13:00:47
Done.
|
| + MessageKind.OPERATOR_NAMED_ARGUMENTS.error([function.name]), |
| + Diagnostic.ERROR); |
| + } else { |
| + compiler.reportMessage( |
| + compiler.spanFromElement(function), |
|
ahe
2013/01/09 10:17:52
Ditto.
Johnni Winther
2013/01/09 13:00:47
Done.
|
| + MessageKind.OPERATOR_OPTIONAL_ARGUMENTS.error([function.name]), |
| + Diagnostic.ERROR); |
| + } |
| + } |
| + } |
| + |
| reportErrorWithContext(Element errorneousElement, |
| MessageKind errorMessage, |
| Element contextElement, |