Skip to content

Commit

Permalink
GROOVY-11363: SC: support primitiveValue::boxedClassMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Apr 24, 2024
1 parent bc26ebc commit 6ced541
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public void writeMethodReferenceExpression(final MethodReferenceExpression metho
ClassNode typeOrTargetRefType = isClassExpression ? typeOrTargetRef.getType()
: controller.getTypeChooser().resolveType(typeOrTargetRef, classNode);

if (ClassHelper.isPrimitiveType(typeOrTargetRefType)) // GROOVY-11353
typeOrTargetRefType = ClassHelper.getWrapper(typeOrTargetRefType);

ClassNode[] methodReferenceParamTypes = methodReferenceExpression.getNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS);
Parameter[] parametersWithExactType = createParametersWithExactType(abstractMethod, methodReferenceParamTypes);
String methodRefName = methodReferenceExpression.getMethodName().getText();
Expand Down Expand Up @@ -126,6 +129,7 @@ public void writeMethodReferenceExpression(final MethodReferenceExpression metho
isClassExpression = true;
} else {
typeOrTargetRef.visit(controller.getAcg());
controller.getOperandStack().box(); // GROOVY-11353
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/test/groovy/transform/stc/MethodReferenceTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ final class MethodReferenceTest {
'''
}

@Test // GROOVY-10813
@Test // GROOVY-10813, GROOVY-11363
void testMethodSelection2() {
for (spec in ['', '<?>', '<Object>', '<? extends Object>', '<? super String>']) {
assertScript imports + """
Expand Down Expand Up @@ -1353,6 +1353,16 @@ final class MethodReferenceTest {
assert result == 'x'
}
test()
'''
assertScript imports + '''
@CompileStatic
void test() {
Supplier<String> s = 0::toString
def result = s.get()
assert result == '0'
}
test()
'''
}
Expand Down

0 comments on commit 6ced541

Please sign in to comment.