Skip to content

Commit

Permalink
Fix for #1024: Map<String,Object> for named args list
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 20, 2020
1 parent e02503d commit f678488
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3479,4 +3479,16 @@ public void testMethodOverloadsArgumentMatching9() {

assertType(contents, "n", "java.lang.Number");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1024
public void testMethodOverloadsArgumentMatching10() {
String contents =
"byte meth(String s) {\n" +
"}\n" +
"char meth(Map args) {\n" +
"}\n" +
"meth(name:null)\n";

assertType(contents, "meth", "java.lang.Character");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2101,9 +2101,18 @@ private MethodNode findLazyMethod(final String fieldName) {
private List<ClassNode> getMethodCallArgumentTypes(ASTNode node) {
if (node instanceof MethodCall) {
Expression arguments = ((MethodCall) node).getArguments();
if (arguments instanceof ArgumentListExpression) {
List<Expression> expressions = ((ArgumentListExpression) arguments).getExpressions();
if (arguments instanceof TupleExpression) {
List<Expression> expressions = ((TupleExpression) arguments).getExpressions();
if (isNotEmpty(expressions)) {
if (expressions.get(0) instanceof NamedArgumentListExpression) {
if (node instanceof ConstructorCallExpression) {
return Collections.emptyList(); // default constructor
} else {
return Collections.singletonList(createParameterizedMap(
VariableScope.STRING_CLASS_NODE, VariableScope.OBJECT_CLASS_NODE));
}
}

List<ClassNode> types = new ArrayList<>(expressions.size());
for (Expression expression : expressions) {
ClassNode exprType = expression.getType();
Expand Down Expand Up @@ -2150,7 +2159,6 @@ private List<ClassNode> getMethodCallArgumentTypes(ASTNode node) {
return types;
}
}
// TODO: Might be useful to look into TupleExpression
return Collections.emptyList();
}

Expand Down

0 comments on commit f678488

Please sign in to comment.