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

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

Issue 11778039: Report arity errors on user definable operators. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: co19-dart2dart.status updated Created 7 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 side-by-side diff with in-line comments
Download patch
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,
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart2jslib.dart ('k') | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698