This is an automated email from the ASF dual-hosted git repository.
sunlan 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 873cc78381 GROOVY-11659: STC: support assigning of collection to
primitive array (#2258)
873cc78381 is described below
commit 873cc78381cc1a5a801f8388d9fe9d8f5f6b87d7
Author: Eric Milles <[email protected]>
AuthorDate: Sat Jun 28 14:25:46 2025 -0500
GROOVY-11659: STC: support assigning of collection to primitive array
(#2258)
---
.../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]'