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 <eric.mil...@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]'