Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 6f5dfffb0 -> 8c1e78986


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/8c1e7898
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8c1e7898
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8c1e7898

Branch: refs/heads/GROOVY_2_4_X
Commit: 8c1e789864f17cc0c1fe7135397abcb15b431e93
Parents: 6f5dfff
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:53:55 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/8c1e7898/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 ef0064a..6832624 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2350,10 +2350,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/8c1e7898/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