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 2025/06/25 14:16:43 UTC

(groovy) branch GROOVY-11659 created (now e82efe85ca)

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

emilles pushed a change to branch GROOVY-11659
in repository https://gitbox.apache.org/repos/asf/groovy.git


      at e82efe85ca GROOVY-11659: STC: support assigning of collection to primitive array

This branch includes the following new commits:

     new e82efe85ca GROOVY-11659: STC: support assigning of collection to primitive array

The 1 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.



(groovy) 01/01: GROOVY-11659: STC: support assigning of collection to primitive array

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

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

commit e82efe85cad158a7e4e346705e98d913a7f991e3
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Jun 25 08:57:54 2025 -0500

    GROOVY-11659: STC: support assigning of collection to primitive array
---
 .../groovy/transform/stc/StaticTypeCheckingSupport.java     |  2 +-
 .../groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 80d73568c0..c030eb3cca 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -666,7 +666,7 @@ public abstract class StaticTypeCheckingSupport {
             if (GeneralUtils.isOrImplements(right, Collection_TYPE)) {
                 var elementType = GenericsUtils.parameterizeType(right, Collection_TYPE).getGenericsTypes()[0];
                 return isObjectType(leftItemType) // Object[] can accept any collection element type(s)
-                    || (elementType.getLowerBound() == null && isCovariant(extractType(elementType), leftItemType));
+                    || (elementType.getLowerBound() == null && isCovariant(extractType(elementType), getWrapper(leftItemType)));
                     //  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ GROOVY-8984: "? super T" is only compatible with an Object[] target
             }
             if (GeneralUtils.isOrImplements(right, BaseStream_TYPE)) {
diff --git a/src/test/groovy/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy b/src/test/groovy/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy
index 4ade3f26c6..3bc268d00c 100644
--- a/src/test/groovy/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy
+++ b/src/test/groovy/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy
@@ -781,6 +781,19 @@ class ArraysAndCollectionsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-11659
+    void testShouldAllowArrayAssignment7() {
+        assertScript '''
+            Integer[] objects = 1..10
+            int [] primitives = 1..10 // TODO: long[]
+
+            assert objects.length == 10
+            assert objects[0] instanceof Integer i && i == 1
+            assert primitives.length == 10
+            assert primitives[0] == 1 && primitives[9] == 10
+        '''
+    }
+
     // GROOVY-11070
     void testNumberArrayGet() {
         String array = 'int[] array = [0, 1, 2, 3]'