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/09/05 20:44:50 UTC

(groovy) branch master updated: GROOVY-11448: STC: `subList` bounds check

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f40842b771 GROOVY-11448: STC: `subList` bounds check
f40842b771 is described below

commit f40842b7717c59402561150d5fd22c01afb661a0
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Sep 5 15:35:11 2024 -0500

    GROOVY-11448: STC: `subList` bounds check
---
 .../codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java | 2 +-
 src/test/groovy/transform/stc/ClosuresSTCTest.groovy             | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 7c0dae50f2..0b19fe022e 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4037,7 +4037,7 @@ out:                if (mn.size() != 1) {
             checkForbiddenSpreadArgument(arguments);
         } else { // GROOVY-10597: allow spread for the ... param
             List<Expression> list = arguments.getExpressions();
-            list = list.subList(0, parameters.length - 1);
+            list = list.subList(0, Math.min(parameters.length - 1, list.size())); // GROOVY-11448
             checkForbiddenSpreadArgument(args(list));
         }
     }
diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index 0fee303c64..65781ba625 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -179,6 +179,15 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
         'Cannot call closure that accepts [java.lang.Object, java.lang.Object] with [java.lang.String]'
     }
 
+    // GROOVY-11448
+    void testCallClosure18() {
+        assertScript '''
+            def c = { int x = 0, int[] y = new int[0] -> return x }
+            assert c( ) == 0
+            assert c(1) == 1
+        '''
+    }
+
     void testClosureReturnTypeInference1() {
         assertScript '''
             def c = { int a, int b -> return a + b }