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 2021/04/12 16:59:42 UTC
[groovy] 01/01: GROOVY-10034: do not cast non-primitive array when
target is Object[]
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY-10034
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit abeced9ca81397feb2f2457fe33cb4519f97a8d2
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Apr 12 11:59:27 2021 -0500
GROOVY-10034: do not cast non-primitive array when target is Object[]
---
.../org/codehaus/groovy/classgen/asm/OperandStack.java | 6 ++++++
src/test/groovy/bugs/Groovy10034.groovy | 17 +++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java b/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
index 4de5957..ec75c58 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
@@ -338,6 +338,12 @@ public class OperandStack {
return;
}
+ // GROOVY-10034: no need to cast non-primitive array when target is "java.lang.Object[]"
+ if (targetType.isArray() && targetType.getComponentType().equals(ClassHelper.OBJECT_TYPE)
+ && top.isArray() && !ClassHelper.isPrimitiveType(top.getComponentType())) {
+ return;
+ }
+
boolean primTarget = ClassHelper.isPrimitiveType(targetType);
boolean primTop = ClassHelper.isPrimitiveType(top);
diff --git a/src/test/groovy/bugs/Groovy10034.groovy b/src/test/groovy/bugs/Groovy10034.groovy
new file mode 100644
index 0000000..670ac36
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10034.groovy
@@ -0,0 +1,17 @@
+package groovy.bugs
+
+import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase
+
+final class Groovy10034 extends AbstractBytecodeTestCase {
+ void testObjectArrayParam() {
+ def result = compile method:'test', '''
+ @groovy.transform.CompileStatic
+ def test() {
+ ["x"].toArray(new String[0])
+ }
+ '''
+ int offset = result.indexOf('ANEWARRAY java/lang/String', result.indexOf('--BEGIN--'))
+ assert result.hasStrictSequence(['ANEWARRAY java/lang/String','INVOKEINTERFACE java/util/List.toArray'], offset)
+ // there should be no 'INVOKEDYNAMIC cast' instruction here: ^
+ }
+}