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 2019/12/11 20:39:27 UTC

[groovy] branch master updated: fix class config for wildcard types

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

emilles 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 1e3dfbc  fix class config for wildcard types
1e3dfbc is described below

commit 1e3dfbc0414a38f3214ee061ad63cfab40da2003
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Dec 11 14:39:11 2019 -0600

    fix class config for wildcard types
    
    beware of [Object] for upper bounds; often it's <? super T> or just <?>
---
 .../org/codehaus/groovy/vmplugin/v5/Java5.java     | 24 +++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index db0fc3f..f3e9aab 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -150,23 +150,23 @@ public class Java5 implements VMPlugin {
         return node.makeArray();
     }
 
-    private ClassNode configureWildcardType(WildcardType wildcardType) {
+    private ClassNode configureWildcardType(final WildcardType wildcardType) {
         ClassNode base = ClassHelper.makeWithoutCaching("?");
         base.setRedirect(ClassHelper.OBJECT_TYPE);
-        //TODO: more than one lower bound for wildcards?
-        ClassNode[] lowers = configureTypes(wildcardType.getLowerBounds());
-        ClassNode lower = null;
-        // TODO: is it safe to remove this? What was the original intention?
-        if (lowers != null) lower = lowers[0];
 
-        ClassNode[] upper = configureTypes(wildcardType.getUpperBounds());
-        GenericsType t = new GenericsType(base, upper, lower);
-        t.setWildcard(true);
+        ClassNode[] lowers = configureTypes(wildcardType.getLowerBounds());
+        ClassNode[] uppers = configureTypes(wildcardType.getUpperBounds());
+        // beware of [Object] upper bounds; often it's <?> or <? super T>
+        if (lowers != null || wildcardType.getTypeName().equals("?")) {
+            uppers = null;
+        }
 
-        ClassNode ref = ClassHelper.makeWithoutCaching(Object.class, false);
-        ref.setGenericsTypes(new GenericsType[]{t});
+        GenericsType gt = new GenericsType(base, uppers, lowers != null ? lowers[0] : null);
+        gt.setWildcard(true);
 
-        return ref;
+        ClassNode wt = ClassHelper.makeWithoutCaching(Object.class, false);
+        wt.setGenericsTypes(new GenericsType[]{gt});
+        return wt;
     }
 
     private ClassNode configureParameterizedType(ParameterizedType parameterizedType) {