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

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

Issue 11783089: Fix VariableDefinitions.endToken for formal parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years, 10 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 bc9081324c0d69d188c02d8720c795e2460056ce..c76ea40293e9ee449ccc3547b442ade8d8f9373a 100644
--- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -691,13 +691,16 @@ class ResolverTask extends CompilerTask {
if (value == null) return;
if (!(isUserDefinableOperator(value) || identical(value, 'unary-'))) return;
+ bool isMinus = false;
int requiredParameterCount;
MessageKind messageKind;
FunctionSignature signature = function.computeSignature(compiler);
if (identical(value, 'unary-')) {
+ isMinus = true;
messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY;
requiredParameterCount = 0;
} else if (isMinusOperator(value)) {
+ isMinus = true;
messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY;
requiredParameterCount = 1;
} else if (isUnaryOperator(value)) {
@@ -713,17 +716,40 @@ class ResolverTask extends CompilerTask {
compiler.internalErrorOnElement(function,
'Unexpected user defined operator $value');
}
- checkArity(function, requiredParameterCount, messageKind);
+ checkArity(function, requiredParameterCount, messageKind, isMinus);
}
void checkArity(FunctionElement function,
- int requiredParameterCount, MessageKind messageKind) {
+ int requiredParameterCount, MessageKind messageKind,
+ bool isMinus) {
FunctionExpression node = function.parseNode(compiler);
FunctionSignature signature = function.computeSignature(compiler);
if (signature.requiredParameterCount != requiredParameterCount) {
Node errorNode = node;
if (node.parameters != null) {
- if (signature.requiredParameterCount < requiredParameterCount) {
+ if (isMinus ||
+ signature.requiredParameterCount < requiredParameterCount) {
+ // If there are too few parameters, point to the whole parameter list.
+ // For instance
+ //
+ // int operator +() {}
+ // ^^
+ //
+ // int operator []=(value) {}
+ // ^^^^^^^
+ //
+ // For operator -, always point the whole parameter list, like
+ //
+ // int operator -(a, b) {}
+ // ^^^^^^
+ //
+ // instead of
+ //
+ // int operator -(a, b) {}
+ // ^
+ //
+ // since the correction might not be to remove 'b' but instead to
+ // remove 'a, b'.
errorNode = node.parameters;
} else {
errorNode = node.parameters.nodes.skip(requiredParameterCount).head;

Powered by Google App Engine
This is Rietveld 408576698