diff --git a/typechecker/src/com/redhat/ceylon/compiler/typechecker/analyzer/ExpressionVisitor.java b/typechecker/src/com/redhat/ceylon/compiler/typechecker/analyzer/ExpressionVisitor.java index b6eb1c34b74..e1e1c416265 100644 --- a/typechecker/src/com/redhat/ceylon/compiler/typechecker/analyzer/ExpressionVisitor.java +++ b/typechecker/src/com/redhat/ceylon/compiler/typechecker/analyzer/ExpressionVisitor.java @@ -4336,6 +4336,8 @@ else if (arg instanceof Tree.Comprehension) { else { checkPositionalArgument(param, pr, (Tree.ListedArgument) arg); + checkPositionalArgumentPosition( + i, param, args); } } } @@ -4743,6 +4745,48 @@ private void checkPositionalArgument(Parameter p, } } + /** + * Warns if argument and parameter names don't match (#6172) + */ + private void checkPositionalArgumentPosition( + int paramIndex, Parameter param, List args) { + String paramName = param.getName(); + if (paramIndex < args.size()) { + Tree.PositionalArgument currentArg = args.get(paramIndex); + if (currentArg instanceof Tree.ListedArgument) { + Tree.Term currentArgTerm = unwrapExpressionUntilTerm( + ((Tree.ListedArgument)currentArg).getExpression()); + if (currentArgTerm instanceof Tree.BaseMemberExpression) { + String currentArgName = ((Tree.BaseMemberExpression)currentArgTerm) + .getIdentifier().getText(); + if (currentArgName.equals(paramName)) { + return; + } + } + } + } + for (int otherArgIndex = 0; otherArgIndex < args.size(); otherArgIndex++) { + if (otherArgIndex == paramIndex) continue; + Tree.PositionalArgument otherArg = args.get(otherArgIndex); + if (otherArg instanceof Tree.ListedArgument) { + Tree.Term otherArgTerm = unwrapExpressionUntilTerm( + ((Tree.ListedArgument)otherArg).getExpression()); + if (otherArgTerm instanceof Tree.BaseMemberExpression) { + String otherArgName = ((Tree.BaseMemberExpression)otherArgTerm) + .getIdentifier().getText(); + if (otherArgName.equals(paramName)) { + otherArg.addUsageWarning( + Warning.suspiciousArgument, + "argument '" + otherArgName + + "' does not assign to parameter '" + + paramName + "'; consider using named arguments " + + "if this is intentional"); + } + } + } + } + } + @Override public void visit(Tree.Comprehension that) { super.visit(that); Tree.InitialComprehensionClause icc = diff --git a/typechecker/src/com/redhat/ceylon/compiler/typechecker/analyzer/Warning.java b/typechecker/src/com/redhat/ceylon/compiler/typechecker/analyzer/Warning.java index 24c196827be..f36bc15c6cc 100644 --- a/typechecker/src/com/redhat/ceylon/compiler/typechecker/analyzer/Warning.java +++ b/typechecker/src/com/redhat/ceylon/compiler/typechecker/analyzer/Warning.java @@ -20,5 +20,6 @@ public enum Warning { javaAnnotationElement, syntaxDeprecation, smallIgnored, - literalNotSmall -} \ No newline at end of file + literalNotSmall, + suspiciousArgument +}