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 2022/02/19 20:08:34 UTC

[groovy] branch GROOVY_2_5_X updated: GROOVY-9918: produce varargs binding when one arg short despite arg type

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

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


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new 5b7381a  GROOVY-9918: produce varargs binding when one arg short despite arg type
5b7381a is described below

commit 5b7381ab9e082f064060dccbf6321be2b45dfa80
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Feb 19 14:00:26 2022 -0600

    GROOVY-9918: produce varargs binding when one arg short despite arg type
    
    2_5_X backport
---
 .../classgen/asm/sc/StaticInvocationWriter.java    |  2 +-
 .../classgen/asm/sc/BugsStaticCompileTest.groovy   | 29 ++++++++++++++++++++--
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
index 1650c4d..c994176 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -448,7 +448,7 @@ public class StaticInvocationWriter extends InvocationWriter {
                 typeChooser.resolveType(argumentList.get(argumentListSize -1), controller.getClassNode()):null;
         if (lastParaType.isArray() && (
                 argumentListSize > para.length
-                || (argumentListSize == (para.length - 1) && !lastParaType.equals(lastArgType))
+                || argumentListSize == (para.length - 1)
                 || (argumentListSize == para.length && lastArgType != null && !lastArgType.isArray()
                     && (StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(lastArgType, lastParaType.getComponentType())
                         || ClassHelper.GSTRING_TYPE.equals(lastArgType) && ClassHelper.STRING_TYPE.equals(lastParaType.getComponentType())))
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
index 72d8508..b6c9f7d 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -946,14 +946,39 @@ final class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilati
     // GROOVY-6113
     void testCallObjectVargsMethodWithPrimitiveIntConstant() {
         assertScript '''
-            int sum(Object... elems) {
-                 (Integer)elems.toList().sum()
+            int sum(... zeroOrMore) {
+                 (Integer) zeroOrMore.toList().sum()
             }
             int x = sum(Closure.DELEGATE_FIRST)
             assert x == Closure.DELEGATE_FIRST
         '''
     }
 
+    // GROOVY-9918
+    void testCallObjectObjectVargsMethodWithObjectArray() {
+        assertScript '''
+            def m(one, ... zeroOrMore) {
+            }
+            Object[] array = ['a', 'b']
+            m(array) // NPE in SC
+        '''
+    }
+
+    void testDefaultArgumentAndVargs() {
+        assertScript '''
+            def m(int x=1, int y, String[] z) {
+                [x as String, y as String] + Arrays.asList(z)
+            }
+            assert m(2,'3') == ['1','2','3']
+        '''
+        assertScript '''
+            def m(int x, int y=2, String[] z) {
+                [x as String, y as String] + Arrays.asList(z)
+            }
+            assert m(1,'3') == ['1','2','3']
+        '''
+    }
+
     // GROOVY-6095
     void testServletError() {
         assertScript '''