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/11/18 20:22:37 UTC

[groovy] branch GROOVY_4_0_X updated: GROOVY-10846: STC: use erasure for placeholder with no upper bound

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

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


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new d72a1ac5d5 GROOVY-10846: STC: use erasure for placeholder with no upper bound
d72a1ac5d5 is described below

commit d72a1ac5d5e1e052016838385a36506f320e9aa8
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Nov 18 13:30:49 2022 -0600

    GROOVY-10846: STC: use erasure for placeholder with no upper bound
---
 .../transform/stc/StaticTypeCheckingVisitor.java      |  3 ++-
 src/test/groovy/transform/stc/GenericsSTCTest.groovy  | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

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 9738aa3d19..70c06d038c 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3865,7 +3865,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                 addSelfTypes(cn, owners);
             }
         } else {
-            owners.add(Receiver.make(OBJECT_TYPE)); // T or T super Type
+            ClassNode cn = gt.getType().redirect(); // GROOVY-10846
+            owners.add(Receiver.make(cn)); // T or T super Type
         }
     }
 
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index c8dabe9f87..9be6113b81 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -4161,6 +4161,25 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10846
+    void testClassLevelGenericsForPropertyRead() {
+        for (vis in ['','public','protected','@groovy.transform.PackageScope']) {
+            assertScript """
+                class A {
+                    $vis String b
+                }
+                class C<X extends A, Y extends List<X>> {
+                    void test(X x) {
+                        x.b = 'blah'
+                    }
+                }
+                A a = []
+                new C<A, List<A>>().test(a)
+                assert a.b == 'blah'
+            """
+        }
+    }
+
     // GROOVY-6919
     void testMethodLevelGenericsForPropertyRead() {
         assertScript '''