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 2022/02/05 01:52:56 UTC

[groovy] branch GROOVY_3_0_X updated: GROOVY-10461: query `DecompiledClassNode` parameterized without resolve

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

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


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 13079c1  GROOVY-10461: query `DecompiledClassNode` parameterized without resolve
13079c1 is described below

commit 13079c19cc4aa8b40648017dfc230bf1251ad63b
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Feb 4 19:13:27 2022 -0600

    GROOVY-10461: query `DecompiledClassNode` parameterized without resolve
---
 .../codehaus/groovy/ast/tools/GenericsUtils.java   | 25 ++++++++++++++--------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index eddfb9d..1961e00 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -28,6 +28,7 @@ import org.codehaus.groovy.ast.GenericsType;
 import org.codehaus.groovy.ast.MethodNode;
 import org.codehaus.groovy.ast.ModuleNode;
 import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.decompiled.DecompiledClassNode;
 import org.codehaus.groovy.ast.expr.DeclarationExpression;
 import org.codehaus.groovy.ast.stmt.EmptyStatement;
 import org.codehaus.groovy.ast.stmt.ExpressionStatement;
@@ -271,16 +272,22 @@ public class GenericsUtils {
 
     }
 
-    public static ClassNode nonGeneric(ClassNode type) {
-        if (type.isUsingGenerics()) {
-            final ClassNode nonGen = ClassHelper.makeWithoutCaching(type.getName());
-            nonGen.setRedirect(type);
-            nonGen.setGenericsTypes(null);
-            nonGen.setUsingGenerics(false);
-            return nonGen;
+    public static ClassNode nonGeneric(final ClassNode type) {
+        int dims = 0;
+        ClassNode temp = type;
+        while (temp.isArray()) { dims += 1;
+            temp = temp.getComponentType();
         }
-        if (type.isArray() && type.getComponentType().isUsingGenerics()) {
-            return type.getComponentType().getPlainNodeReference().makeArray();
+        if (temp instanceof DecompiledClassNode // GROOVY-10461: check without resolving supers
+                        ? ((DecompiledClassNode) temp).isParameterized() : temp.isUsingGenerics()) {
+            ClassNode result = ClassHelper.makeWithoutCaching(temp.getName());
+            result.setRedirect(temp);
+            result.setGenericsTypes(null);
+            result.setUsingGenerics(false);
+            while (dims > 0) { dims -= 1;
+                result = result.makeArray();
+            }
+            return result;
         }
         return type;
     }