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/10/24 20:55:50 UTC

[groovy] branch master updated: GROOVY-10109, GROOVY-10120: STC: access via public bridge method

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 63515db245 GROOVY-10109, GROOVY-10120: STC: access via public bridge method
63515db245 is described below

commit 63515db24581d2c516f21b58e253bcce6d9d130d
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Oct 24 15:14:08 2022 -0500

    GROOVY-10109, GROOVY-10120: STC: access via public bridge method
---
 .../transform/stc/StaticTypeCheckingSupport.java   |  8 +++----
 src/test/groovy/transform/stc/BugsSTCTest.groovy   |  9 ++++++++
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 26 +++++++++++++++++-----
 3 files changed, 33 insertions(+), 10 deletions(-)

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 9b5af44147..8f7ebac010 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1202,8 +1202,7 @@ public abstract class StaticTypeCheckingSupport {
         List<MethodNode> list = new ArrayList<>(new LinkedHashSet<>(collection)), toBeRemoved = new ArrayList<>();
         for (int i = 0, n = list.size(); i < n - 1; i += 1) {
             MethodNode one = list.get(i);
-            if (toBeRemoved.contains(one)) continue;
-            for (int j = i + 1; j < n; j += 1) {
+            for (int j = i + 1; j < n && !toBeRemoved.contains(one); j += 1) {
                 MethodNode two = list.get(j);
                 if (toBeRemoved.contains(two)) continue;
                 if (one.getParameters().length == two.getParameters().length) {
@@ -1230,11 +1229,10 @@ public abstract class StaticTypeCheckingSupport {
                     } else if (!oneDC.equals(twoDC)) {
                         if (ParameterUtils.parametersEqual(one.getParameters(), two.getParameters())) {
                             // GROOVY-6882, GROOVY-6970: drop overridden or interface equivalent method
-                            // GROOVY-8638, GROOVY-10120: unless bridge method (synthetic variant) overrides
                             if (twoDC.isInterface() ? oneDC.implementsInterface(twoDC) : oneDC.isDerivedFrom(twoDC)) {
-                                toBeRemoved.add(isSynthetic(one, two) ? one : two);
+                                toBeRemoved.add(two);
                             } else if (oneDC.isInterface() ? (disjoint ? twoDC.implementsInterface(oneDC) : twoDC.isInterface()) : twoDC.isDerivedFrom(oneDC)) {
-                                toBeRemoved.add(isSynthetic(two, one) ? two : one);
+                                toBeRemoved.add(one);
                             }
                         }
                     }
diff --git a/src/test/groovy/transform/stc/BugsSTCTest.groovy b/src/test/groovy/transform/stc/BugsSTCTest.groovy
index 10d40486bb..15fedb03a7 100644
--- a/src/test/groovy/transform/stc/BugsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/BugsSTCTest.groovy
@@ -1116,6 +1116,15 @@ Printer
         '''
     }
 
+    // GROOVY-10109
+    void testInvokePublicMethodFromInaccessibleBase() {
+        assertScript '''
+            new StringBuilder().with {
+                assert length() == 0 // access error
+            }
+        '''
+    }
+
     void testInvokeSuperMethodFromCovariantOverride() {
         assertScript '''
             abstract class A { int i = 0
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index a857a51834..3f1a294afc 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -518,14 +518,11 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
-    // GROOVY-8638, GROOVY-10120
     void testReturnTypeInferenceWithMethodGenerics18() {
-        String guava = '''
+        assertScript '''
             @Grab('com.google.guava:guava:31.1-jre')
             import com.google.common.collect.*
-        '''
 
-        assertScript guava + '''
             ListMultimap<String, Integer> mmap = ArrayListMultimap.create()
 
             Map<String, Collection<Integer>> map = mmap.asMap()
@@ -535,8 +532,27 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
                 Collection<Integer> values = entry.value
             }
         '''
+    }
+
+    // GROOVY-8638
+    void testReturnTypeInferenceWithMethodGenerics18a() {
+        shouldFailWithMessages '''
+            @Grab('com.google.guava:guava:31.1-jre')
+            import com.google.common.collect.*
+
+            def mmap = (ListMultimap<String, Integer>) ArrayListMultimap.create()
+            Map<String, Set<Integer>> map = mmap.asMap()
+        ''',
+        'Cannot assign java.util.Map<java.lang.String, java.util.Collection<java.lang.Integer>> to: java.util.Map<java.lang.String, java.util.Set<java.lang.Integer>>'
+    }
+
+    // GROOVY-10120
+    @NotYetImplemented
+    void testReturnTypeInferenceWithMethodGenerics18b() {
+        shouldFailWithMessages '''
+            @Grab('com.google.guava:guava:31.1-jre')
+            import com.google.common.collect.*
 
-        shouldFailWithMessages guava + '''
             ListMultimap<String, Integer> mmap = ArrayListMultimap.create()
             Map<String, Set<Integer>> map = mmap.asMap() // ArrayListMultimap#asMap() is bridge and lacks generics
         ''',