Skip to content

Commit

Permalink
GROOVY-9763
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Oct 6, 2020
1 parent 9ddae89 commit 632e2bd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Expand Up @@ -2674,4 +2674,29 @@ public void testTraits9760() {

runConformTest(sources, "works");
}

@Test
public void testTraits9763() {
//@formatter:off
String[] sources = {
"Script.groovy",
"@groovy.transform.CompileStatic\n" +
"void test() {\n" +
" C.m({ -> print 'works'; return 0 })\n" +
"}\n" +
"test()\n",

"C.groovy",
"class C implements T {\n" +
"}\n",

"T.groovy",
"trait T {\n" +
" static <U> U m(Closure<U> callable) { callable.call() }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "works");
}
}
Expand Up @@ -143,12 +143,18 @@ private static void applyTrait(final ClassNode trait, final ClassNode cNode, fin
Parameter[] origParams = new Parameter[helperMethodParams.length - 1];
Parameter[] params = new Parameter[helperMethodParams.length - 1];
System.arraycopy(methodNode.getParameters(), 1, params, 0, params.length);
/* GRECLIPSE edit -- GROOVY-9763
Map<String,ClassNode> methodGenericsSpec = new LinkedHashMap<String, ClassNode>(genericsSpec);
MethodNode originalMethod = trait.getMethod(name, params);
// Original method may be null for the case of private or static methods
if (originalMethod!=null) {
methodGenericsSpec = GenericsUtils.addMethodGenerics(originalMethod, methodGenericsSpec);
}
*/
MethodNode originalMethod = trait.getMethod(name, params);
Map<String, ClassNode> methodGenericsSpec = GenericsUtils.addMethodGenerics(
originalMethod != null ? originalMethod : methodNode, genericsSpec);
// GRECLIPSE end
for (int i = 1; i < helperMethodParams.length; i++) {
Parameter parameter = helperMethodParams[i];
ClassNode originType = parameter.getOriginType();
Expand Down
Expand Up @@ -142,8 +142,13 @@ private static void applyTrait(final ClassNode trait, final ClassNode cNode, fin
Parameter[] params = new Parameter[nParams - 1];
System.arraycopy(methodNode.getParameters(), 1, params, 0, params.length);
MethodNode originalMethod = trait.getMethod(name, params);
/* GRECLIPSE edit -- GROOVY-9763
Map<String, ClassNode> methodGenericsSpec = Optional.ofNullable(originalMethod)
.map(m -> GenericsUtils.addMethodGenerics(m, genericsSpec)).orElse(genericsSpec);
*/
Map<String, ClassNode> methodGenericsSpec = GenericsUtils.addMethodGenerics(
Optional.ofNullable(originalMethod).orElse(methodNode), genericsSpec);
// GRECLIPSE end
for (int i = 1; i < nParams; i += 1) {
Parameter parameter = helperMethodParams[i];
ClassNode originType = parameter.getOriginType();
Expand Down

0 comments on commit 632e2bd

Please sign in to comment.