You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by GitBox <gi...@apache.org> on 2021/04/12 17:20:40 UTC

[GitHub] [groovy] danielsun1106 commented on a change in pull request #1556: GROOVY-10034: do not cast non-primitive array when target is Object[]

danielsun1106 commented on a change in pull request #1556:
URL: https://github.com/apache/groovy/pull/1556#discussion_r611815705



##########
File path: src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
##########
@@ -338,6 +338,12 @@ private void doConvertAndCast(ClassNode targetType, final boolean coerce) {
             return;
         }
 
+        // GROOVY-10034: no need to cast non-primitive array when target is "java.lang.Object[]"

Review comment:
       How about making the check more general? If the `top` component type is inherited from `target` component type, no need to cast type. The following code could be tweaked as:
   ```java
           if (targetType.isArray() && !ClassHelper.isPrimitiveType(targetType.getComponentType()) 
                     && top.isArray() && !ClassHelper.isPrimitiveType(top.getComponentType())
                     && targetType.getComponentType().isAssignableFrom(top.getComponentType())) {
               return;
           }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org