Repository: groovy
Updated Branches:
  refs/heads/master 99f40916f -> aa0e7b786


GROOVY-7784: TypeChecked/CompileStatic: IndexOutOfBoundsException (closes #339)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/aa0e7b78
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/aa0e7b78
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/aa0e7b78

Branch: refs/heads/master
Commit: aa0e7b786b67e709afbf2bffb0c24979e1fd86ad
Parents: 99f4091
Author: paulk <pa...@asert.com.au>
Authored: Thu May 26 23:27:55 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Fri May 27 09:52:32 2016 +1000

----------------------------------------------------------------------
 .../transform/stc/StaticTypeCheckingVisitor.java   |  9 +++++++--
 .../classgen/asm/sc/BugsStaticCompileTest.groovy   | 17 +++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/aa0e7b78/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java 
b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 76d4249..e3cc081 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2352,10 +2352,15 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
         extractGenericsConnections(targetMethodDeclarationClassConnections, 
receiver, receiver.redirect());
         // then we use the method with the SAM parameter to get more 
information about the declaration
         Parameter[] parametersOfMethodContainingSAM = 
methodWithSAMParameter.getParameters();
-        for (int i=0; i<parametersOfMethodContainingSAM.length; i++) {
+        for (int i = 0; i < parametersOfMethodContainingSAM.length; i++) {
+            // potentially skip empty varargs
+            if (i == parametersOfMethodContainingSAM.length - 1
+                    && i == originalMethodCallArguments.getExpressions().size()
+                    && parametersOfMethodContainingSAM[i].getType().isArray())
+                continue;
             Expression callArg = originalMethodCallArguments.getExpression(i);
             // we look at the closure later in detail, so skip it here
-            if (callArg==openBlock) continue;
+            if (callArg == openBlock) continue;
             ClassNode parameterType = 
parametersOfMethodContainingSAM[i].getType();
             
extractGenericsConnections(targetMethodDeclarationClassConnections, 
getType(callArg), parameterType);
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/aa0e7b78/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
----------------------------------------------------------------------
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 b0fd07f..da87665 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -1446,5 +1446,22 @@ println someInt
             assert 0.1d
         '''
     }
+
+    // GROOVY-7784
+    void testWithSamAndEmptyVarArgs() {
+        assertScript '''
+            class Foo {
+                static foo(Integer x, Iterable y, String... z) { y.join('-') }
+            }
+
+            class Groovy7784 {
+                static emptyVarArgs() {
+                    Foo.foo(42, { ['foo', 'bar'].iterator() })
+                }
+            }
+
+            assert Groovy7784.emptyVarArgs() == 'foo-bar'
+        '''
+    }
 }
 

Reply via email to