You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2024/04/24 15:54:23 UTC

(groovy) branch GROOVY_3_0_X updated: GROOVY-11363: SC: support `primitiveValue::boxedClassMethod`

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 6ced5414a9 GROOVY-11363: SC: support `primitiveValue::boxedClassMethod`
6ced5414a9 is described below

commit 6ced5414a9a6dd75564cc5e38bd1787bfc7b378d
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Apr 24 09:55:29 2024 -0500

    GROOVY-11363: SC: support `primitiveValue::boxedClassMethod`
---
 .../asm/sc/StaticTypesMethodReferenceExpressionWriter.java   |  4 ++++
 src/test/groovy/transform/stc/MethodReferenceTest.groovy     | 12 +++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
index 6df30b0ecd..2cb4b2a88e 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
@@ -89,6 +89,9 @@ public class StaticTypesMethodReferenceExpressionWriter extends MethodReferenceE
         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();
@@ -126,6 +129,7 @@ public class StaticTypesMethodReferenceExpressionWriter extends MethodReferenceE
                 isClassExpression = true;
             } else {
                 typeOrTargetRef.visit(controller.getAcg());
+                controller.getOperandStack().box(); // GROOVY-11353
             }
         }
 
diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
index 80d4baecea..35c3f43f78 100644
--- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy
+++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
@@ -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 + """
@@ -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()
         '''
     }