You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/10/11 11:10:36 UTC

(groovy) branch GROOVY_5_1_X updated (3cc099b96d -> 06b4176cff)

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

paulk-asert pushed a change to branch GROOVY_5_1_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


    from 3cc099b96d Bump version on GROOVY_5_1_X branch
     new 92936a7316 junit jupiter (MethodSelectionTest)
     new 06b4176cff GROOVY-12439: Regression: BigDecimal silently narrowed to float in overload selection since 4.0.4

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../codehaus/groovy/runtime/MetaClassHelper.java   | 11 ++-
 .../gls/invocation/MethodSelectionTest.groovy      | 96 +++++++++++++++++++++-
 2 files changed, 102 insertions(+), 5 deletions(-)


(groovy) 02/02: GROOVY-12439: Regression: BigDecimal silently narrowed to float in overload selection since 4.0.4

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk-asert pushed a commit to branch GROOVY_5_1_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 06b4176cff89143f2bdd02c61e12942750214847
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Oct 9 00:19:29 2026 +1000

    GROOVY-12439: Regression: BigDecimal silently narrowed to float in overload selection since 4.0.4
    
    (cherry picked from commit e30c99bb6ca3f5028837744c5fc1bf1c9cac7c7e)
---
 .../codehaus/groovy/runtime/MetaClassHelper.java   | 11 +++-
 .../gls/invocation/MethodSelectionTest.groovy      | 69 ++++++++++++++++++++++
 2 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java b/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
index 892bf4ba11..58ff4add53 100644
--- a/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
@@ -229,6 +229,13 @@ public class MetaClassHelper {
             Object.class
     };
 
+    // GROOVY-12439: penalty for the lossy BigInteger/BigDecimal to float/Float conversions,
+    // so that they never tie with or beat a wider alternative; each other argument can lean
+    // at most 3 towards a float candidate, and 254 * 3 < LOSSY for the JVM's 255 argument
+    // maximum, while 255 * (LOSSY + 19) << PRIMITIVE_SHIFT stays well below VARGS_SHIFT,
+    // so, as in Java, a lossy non-varargs method is still preferred over a varargs one
+    private static final int LOSSY = 1 << 10;
+
     private static final int[][] PRIMITIVE_DISTANCE_TABLE = {
             //                    0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19
             /*boolean[0]*/      { 0,  1,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,  2,},
@@ -243,12 +250,12 @@ public class MetaClassHelper {
             /*Integer[9]*/      {18, 19, 14, 15, 12, 13, 16, 17,  1,  0,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,},
             /*long[10]*/        {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,},
             /*Long[11]*/        {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  1,  0,  2,  3,  4,  5,  6,  7,  8,  9,},
-            /*BigInteger[12]*/  {18, 19,  9, 10,  7,  8, 16, 17,  5,  6,  3,  4,  0, 14, 15, 12, 13, 11,  1,  2,},
+            /*BigInteger[12]*/  {18, 19,  9, 10,  7,  8, 16, 17,  5,  6,  3,  4,  0, 14 + LOSSY, 15 + LOSSY, 12, 13, 11,  1,  2,},
             /*float[13]*/       {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  8,  9,  7,  0,  1,  2,  3,  4,  5,  6,},
             /*Float[14]*/       {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  8,  9,  7,  1,  0,  2,  3,  4,  5,  6,},
             /*double[15]*/      {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  8,  9,  7,  5,  6,  0,  1,  2,  3,  4,},
             /*Double[16]*/      {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  8,  9,  7,  5,  6,  1,  0,  2,  3,  4,},
-            /*BigDecimal[17]*/  {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  8,  9,  7,  5,  6,  3,  4,  0,  1,  2,},
+            /*BigDecimal[17]*/  {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  8,  9,  7,  5 + LOSSY,  6 + LOSSY,  3,  4,  0,  1,  2,},
             /*Number[18]*/      {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  8,  9,  7,  5,  6,  3,  4,  2,  0,  1,},
             /*Object[19]*/      {18, 19, 14, 15, 12, 13, 16, 17, 10, 11,  8,  9,  7,  5,  6,  3,  4,  2,  1,  0,},
     };
diff --git a/src/test/groovy/gls/invocation/MethodSelectionTest.groovy b/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
index 12bdc4d9bb..d03799353d 100644
--- a/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
+++ b/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
@@ -285,6 +285,75 @@ final class MethodSelectionTest {
         '''
     }
 
+    // GROOVY-12439
+    @Test
+    void testBDandBIPreferDoubleOverFloat() {
+        for (big in ['5.0', '5G']) {
+            assertScript """
+                class C {
+                    static m(float... x)          { 'float...'  }
+                    static m(double... x)         { 'double...' }
+                    static m2(float a, float b)   { 'float'     }
+                    static m2(double a, double b) { 'double'    }
+                    static m3(Float a, Float b)   { 'Float'     }
+                    static m3(Double a, Double b) { 'Double'    }
+                }
+
+                def z = 1
+                def d = $big
+                assert C.m(d) == 'double...'
+                assert C.m(z, d) == 'double...'
+                assert C.m(5, z, d) == 'double...'
+                assert C.m(1, 2, 3, 4, 5, 6, 7, 8, d) == 'double...'
+                assert C.m(d, d) == 'double...'
+                assert C.m2(z, d) == 'double'
+                assert C.m2(d, z) == 'double'
+                assert C.m2(d, d) == 'double'
+                assert C.m3(z, d) == 'Double'
+
+                // integral arguments alone still select float, as javac does
+                assert C.m(z, 5) == 'float...'
+                assert C.m2(z, 5) == 'float'
+            """
+        }
+    }
+
+    // GROOVY-12439
+    @Test
+    void testBDandBIStillApplicableToFloat() {
+        for (big in ['5.0', '5G']) {
+            assertScript """
+                class C {
+                    static m(float... x)        { x as List }
+                    static m2(float a, float b) { [a, b]    }
+                }
+
+                def d = $big
+                assert C.m(1, d) == [1f, 5f]
+                assert C.m2(1, d) == [1f, 5f]
+            """
+        }
+    }
+
+    // GROOVY-12439
+    @Test
+    void testBDandBIPreferNonVarargsFloatOverVarargsDouble() {
+        for (big in ['5.0', '5G']) {
+            assertScript """
+                class C {
+                    static m(float x)      { 'float'     }
+                    static m(double... x)  { 'double...' }
+                    static m2(Float x)     { 'Float'     }
+                    static m2(Double... x) { 'Double...' }
+                }
+
+                def d = $big
+                assert C.m(d) == 'float'
+                assert C.m2(d) == 'Float'
+            """
+        }
+    }
+
     @Test
     void testCallWithExendedBigDecimal() {
         assertScript '''


(groovy) 01/02: junit jupiter (MethodSelectionTest)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk-asert pushed a commit to branch GROOVY_5_1_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 92936a73165015e5c77e28e8f30a667f246771b4
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Oct 11 20:30:43 2026 +1000

    junit jupiter (MethodSelectionTest)
    
    Co-Authored-By: Claude Opus 5.5 <no...@anthropic.com>
---
 .../gls/invocation/MethodSelectionTest.groovy      | 27 +++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/test/groovy/gls/invocation/MethodSelectionTest.groovy b/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
index 9c0f3698fd..12bdc4d9bb 100644
--- a/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
+++ b/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
@@ -18,12 +18,18 @@
  */
 package gls.invocation
 
-final class MethodSelectionTest extends gls.CompilableTestSupport {
+import org.junit.jupiter.api.Test
+
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
+
+final class MethodSelectionTest {
 
     /**
      * This test ensures Groovy can choose a method based on interfaces.
      * Choosing such an interface should not be hidden by subclasses.
      */
+    @Test
     void testMostSpecificInterface() {
         assertScript '''
             interface A{}
@@ -58,6 +64,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
         '''
     }
 
+    @Test
     void testMostGeneralForNull() {
         // we use the same signatures with different method orders,
         // because we want to catch method ordering bugs
@@ -97,6 +104,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
         '''
     }
 
+    @Test
     void testMethodSelectionException() {
         assertScript '''
             import org.codehaus.groovy.runtime.metaclass.MethodSelectionException as MSE
@@ -116,6 +124,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
     }
 
     // GROOVY-2719
+    @Test
     void testMethodSelectionWithInterfaceVargsMethod() {
         assertScript '''
             public class Thing {}
@@ -129,6 +138,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
     }
 
     // GROOVY-2698
+    @Test
     void testComplexInterfaceInheritance() {
         assertScript '''
             import javax.swing.*
@@ -151,6 +161,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
         '''
     }
 
+    @Test
     void testNullUsageForPrimitivesWithExplicitNull() {
         [byte,int,short,float,double,boolean,char].each { type ->
             assertScript """
@@ -169,6 +180,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
         }
     }
 
+    @Test
     void testNullUsageForPrimitivesWithImplicitNull() {
         [byte,int,short,float,double,boolean,char].each { type ->
             assertScript """
@@ -187,6 +199,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
         }
     }
 
+    @Test
     void testNullUsageForPrimitivesAndOverloading() {
         [byte,int,short,float,double].each { type ->
             assertScript """
@@ -199,7 +212,8 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
         }
     }
 
-    void testPrivateMethodSelectionFromClosure(){
+    @Test
+    void testPrivateMethodSelectionFromClosure() {
         assertScript '''
             class I1 {
                 private foo() {1}
@@ -216,7 +230,8 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
         '''
     }
 
-    void testCachingForNullAndPrimitive(){
+    @Test
+    void testCachingForNullAndPrimitive() {
         assertScript '''
             boolean shaky(boolean defaultValue) {false}
             shaky(false)
@@ -230,6 +245,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
     }
 
     // GROOVY-3977
+    @Test
     void testBDandBIToFloatAutoConversionInMethodSelection() {
         assertScript '''
             class Foo3977 {
@@ -269,6 +285,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
         '''
     }
 
+    @Test
     void testCallWithExendedBigDecimal() {
         assertScript '''
             BigDecimal f (BigDecimal x) {
@@ -286,6 +303,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
     }
 
     // GROOVY-6431
+    @Test
     void testBigDecAndBigIntSubClass() {
         assertScript'''
             class MyDecimal extends BigDecimal {
@@ -307,6 +325,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
         '''
     }
 
+    @Test
     void testVargsClass() {
         assertScript '''
             interface Parent {}
@@ -326,6 +345,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
     }
 
     // GROOVY-5812
+    @Test
     void testDirectMethodCall() {
         assertScript '''
             private String[] getStringArrayDirectly() { ["string_00", "string_01"] }
@@ -343,6 +363,7 @@ final class MethodSelectionTest extends gls.CompilableTestSupport {
     }
 
     // GROOVY-6189, GROOVY-9852
+    @Test
     void testSAMs() {
         // simple direct case
         assertScript '''