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/03/15 17:36:20 UTC

[groovy] branch master updated: GROOVY-10367: STC: diamond inference: skip type witness without generics

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 ff345d6  GROOVY-10367: STC: diamond inference: skip type witness without generics
ff345d6 is described below

commit ff345d6b5de5a0ad4ad5d639d26c4e291542bef0
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Mar 15 12:06:00 2022 -0500

    GROOVY-10367: STC: diamond inference: skip type witness without generics
---
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java    |  5 +++--
 src/test/groovy/transform/stc/GenericsSTCTest.groovy       | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

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 44cea80..6d6c4cd 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1097,9 +1097,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
             if (!argumentList.getExpressions().isEmpty() && constructor != null) {
                 ClassNode type = GenericsUtils.parameterizeType(cceType, cceType);
                 type = inferReturnTypeGenerics(type, constructor, argumentList);
-                if (type.toString(false).indexOf('#') > 0 // GROOVY-9983, GROOVY-10291, GROOVY-10368
+                if (lType.getGenericsTypes() != null // GROOVY-10367: nothing to inspect
+                        && (type.toString(false).indexOf('#') > 0 // GROOVY-9983, GROOVY-10291, GROOVY-10368: unresolved generic
                         // GROOVY-6232, GROOVY-9956: if cce not assignment compatible, process target as additional type witness
-                        || checkCompatibleAssignmentTypes(lType, type, cce) && !GenericsUtils.buildWildcardType(lType).isCompatibleWith(type)) {
+                        || checkCompatibleAssignmentTypes(lType, type, cce) && !GenericsUtils.buildWildcardType(lType).isCompatibleWith(type))) {
                     // allow covariance of each type parameter, but maintain semantics for nested generics
 
                     ClassNode pType = GenericsUtils.parameterizeType(lType, type);
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 363c2f0..3316fd7 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -1182,6 +1182,20 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         }
     }
 
+    // GROOVY-10367
+    void testDiamondInferrenceFromConstructor26() {
+        assertScript '''
+            @groovy.transform.TupleConstructor(defaults=false)
+            class C<X, Y extends X> { // works without Y
+              X x
+            }
+            def <Z extends Number> void test(Z z) {
+              z = new C<>(z).x // Cannot assign value of type Object to variable of type Z
+            }
+            test(null)
+        '''
+    }
+
     // GROOVY-10280
     void testTypeArgumentPropagation() {
         assertScript '''