Skip to content

Commit

Permalink
Fix for issue #502: resolve static members from closure in static scope
Browse files Browse the repository at this point in the history
- handles closures within closures
  • Loading branch information
eric-milles committed Mar 1, 2018
1 parent 5a1aad1 commit 085cfce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ public void testClosure9a() {
assertExprType(contents, "bar", "java.lang.Long");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/502
public void testClosure9b() {
String contents =
"class Foo {\n" +
" static long bar(String arg) {\n" +
" }\n" +
" static void baz() {\n" +
" String a = 'bc'\n" +
" def closure = {\n" +
" [].each {\n" +
" bar(a)\n" + // call static method from closure within closure within static scope
" }\n" +
" }\n" +
" }\n" +
"}";
assertExprType(contents, "bar", "java.lang.Long");
}

@Test
public void testClosure10() {
String contents =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ protected ASTNode findDeclarationForDynamicVariable(VariableExpression var, Clas
if (isLhsExpr) scope.getWormhole().put("lhs", var);
VariableScope.CallAndType cat = outer.getEnclosingMethodCallExpression();
int enclosingResolveStrategy = (cat == null ? 0 : cat.getResolveStrategy(outer.getEnclosingClosure()));
candidate = findDeclarationForDynamicVariable(var, outer.getOwner(), outer, enclosingResolveStrategy);
candidate = findDeclarationForDynamicVariable(var, getBaseDeclaringType(outer.getOwner()), outer, enclosingResolveStrategy);
} else {
candidate = findDeclaration(var.getName(), owner, isLhsExpr, scope.isOwnerStatic(), scope.isFieldAccessDirect(), callArgs);
}
Expand Down

0 comments on commit 085cfce

Please sign in to comment.