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 4ae274b  minor tweaks
4ae274b is described below

commit 4ae274bae0c3376d10752d6c1dd0630ec811feb4
Author: Eric Milles <[email protected]>
AuthorDate: Fri Sep 24 12:58:56 2021 -0500

    minor tweaks
---
 .../java/org/codehaus/groovy/ast/GenericsType.java | 36 +++++++++-------------
 .../transform/stc/StaticTypeCheckingSupport.java   |  2 +-
 .../transform/stc/StaticTypeCheckingVisitor.java   | 10 +++---
 3 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/GenericsType.java 
b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
index e912a8d..d162c1a 100644
--- a/src/main/java/org/codehaus/groovy/ast/GenericsType.java
+++ b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
@@ -196,12 +196,8 @@ public class GenericsType extends ASTNode {
     
//--------------------------------------------------------------------------
 
     /**
-     * Compares this generics type with the provided class node. If the 
provided
-     * class node is compatible with the generics specification, returns true.
-     * Otherwise, returns false. The check is complete, meaning that nested
-     * generics are also checked.
-     *
-     * @return if {@code classNode} is or is not compatible with this generics 
specification
+     * Determines if the provided type is compatible with this specification.
+     * The check is complete, meaning that nested generics are also checked.
      */
     public boolean isCompatibleWith(final ClassNode classNode) {
         GenericsType[] genericsTypes = classNode.getGenericsTypes();
@@ -212,20 +208,20 @@ public class GenericsType extends ASTNode {
             if (genericsTypes == null) {
                 return true;
             }
-            String name = genericsTypes[0].name;
+            String name = genericsTypes[0].getName();
             if (!isWildcard()) {
-                return this.name.equals(name);
+                return name.equals(getName());
             }
             if (getLowerBound() != null) {
                 // check for "? super T" vs "T"
                 ClassNode lowerBound = getLowerBound();
-                if (lowerBound.getUnresolvedName().equals(name)) {
+                if (name.equals(lowerBound.getUnresolvedName())) {
                     return true;
                 }
             } else if (getUpperBounds() != null) {
                 // check for "? extends T & I" vs "T" or "I"
                 for (ClassNode upperBound : getUpperBounds()) {
-                    if (upperBound.getUnresolvedName().equals(name)) {
+                    if (name.equals(upperBound.getUnresolvedName())) {
                         return true;
                     }
                 }
@@ -234,10 +230,9 @@ public class GenericsType extends ASTNode {
             return checkGenerics(classNode);
         }
         if (isWildcard() || isPlaceholder()) {
-            // if the generics spec is a wildcard or a placeholder then check 
the bounds
             ClassNode lowerBound = getLowerBound();
             if (lowerBound != null) {
-                // for a lower bound, perform the upper bound checks with 
reversed arguments
+                // test bound and type in reverse for lower bound vs upper 
bound
                 if (!implementsInterfaceOrIsSubclassOf(lowerBound, classNode)) 
{
                     return false;
                 }
@@ -251,19 +246,16 @@ public class GenericsType extends ASTNode {
                         return false;
                     }
                 }
-                // if the provided classnode is a subclass of the upper bound
-                // then check that the generic types supplied by the class 
node are compatible with
-                // this generics specification
-                // for example, we could have the spec saying List<String> but 
provided classnode
-                // saying List<Integer>
+                // if the provided type is a subclass of the upper bound(s) 
then
+                // check that the generic types supplied are compatible with 
this
+                // for example, this spec could be "Type<X>" but type is 
"Type<Y>"
                 return checkGenerics(classNode);
             }
-            // if there are no bounds, the generic type is basically Object, 
and everything is compatible
+            // if there are no bounds, the generic type is basically Object 
and everything is compatible
             return true;
         }
-        // last, we could have the spec saying List<String> and a classnode 
saying List<Integer> so
-        // we must check that generics are compatible
-        return getType().equals(classNode) && 
compareGenericsWithBound(classNode, type);
+        // not placeholder or wildcard; no covariance allowed for type or 
bound(s)
+        return classNode.equals(getType()) && 
compareGenericsWithBound(classNode, getType());
     }
 
     private static boolean implementsInterfaceOrIsSubclassOf(final ClassNode 
type, final ClassNode superOrInterface) {
@@ -464,7 +456,7 @@ public class GenericsType extends ASTNode {
                                         if (!match) break;
                                     }
                                 }
-                                continue;
+                                continue; // GROOVY-10010
                             }
                         }
                         match = 
redirectBoundType.isCompatibleWith(classNodeType.getType());
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 d79bcf6..5e06288 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1674,7 +1674,7 @@ public abstract class StaticTypeCheckingSupport {
         if (orig.isGenericsPlaceHolder() != copy.isGenericsPlaceHolder()) 
return false;
         if (!orig.equals(copy)) return false;
         GenericsType[] gt1 = orig.getGenericsTypes();
-        GenericsType[] gt2 = orig.getGenericsTypes();
+        GenericsType[] gt2 = copy.getGenericsTypes();
         if ((gt1 == null) ^ (gt2 == null)) return false;
         if (gt1 != gt2) {
             if (gt1.length != gt2.length) return false;
diff --git 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index aa58a9c..a92d25b 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -140,8 +140,7 @@ import java.util.function.BiPredicate;
 import java.util.function.Function;
 import java.util.stream.IntStream;
 
-import static java.util.stream.Collectors.toList;
-import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.*;
 import static org.apache.groovy.util.BeanUtils.capitalize;
 import static org.apache.groovy.util.BeanUtils.decapitalize;
 import static org.codehaus.groovy.ast.ClassHelper.AUTOCLOSEABLE_TYPE;
@@ -3420,7 +3419,7 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
                             GenericsType[] genericsTypes = 
type.getGenericsTypes();
                             if (genericsTypes != null && genericsTypes.length 
== 1
                                     && genericsTypes[0].getLowerBound() == 
null) {
-                                type = getCombinedBoundType(genericsTypes[0]);
+                                type = genericsTypes[0].getType();
                             } else {
                                 type = OBJECT_TYPE;
                             }
@@ -5428,9 +5427,8 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
             // and unknown generics
             if (!GenericsUtils.hasUnresolvedGenerics(at)) continue;
 
-            while (!at.equals(pt) && !isObjectType(at)) {
-                ClassNode sc = GenericsUtils.getSuperClass(at, pt);
-                at = 
applyGenericsContext(GenericsUtils.extractPlaceholders(at), sc);
+            while (!at.equals(pt) && !isObjectType(at) && 
!isGenericsPlaceHolderOrArrayOf(at)) {
+                at = 
applyGenericsContext(GenericsUtils.extractPlaceholders(at), 
getNextSuperClass(at, pt));
             }
 
             // try to resolve placeholder(s) in argument type using parameter 
type

Reply via email to