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

sunlan 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 67aa1ca774 GROOVY-10120: STC: synthetic variant (bridge method) lacks 
generics info
67aa1ca774 is described below

commit 67aa1ca7745aded3568ef2b822ece24853902a0a
Author: Eric Milles <[email protected]>
AuthorDate: Fri Aug 12 12:27:30 2022 -0500

    GROOVY-10120: STC: synthetic variant (bridge method) lacks generics info
    
    (cherry picked from commit f09ea218d6bf0e03c6a4112b29b1ef67b16b501e)
---
 .../groovy/transform/stc/StaticTypeCheckingSupport.java    | 14 ++++++++++----
 src/test/groovy/transform/stc/GenericsSTCTest.groovy       | 12 ++++++++++--
 2 files changed, 20 insertions(+), 6 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 3fb7b069cc..7e828d5745 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1226,19 +1226,20 @@ public abstract class StaticTypeCheckingSupport {
                             // equivalent, for example 
String#compareTo(Object) and
                             // String#compareTo(String) -- in that case, the 
Object
                             // version is marked as synthetic
-                            if (one.isSynthetic() && !two.isSynthetic()) {
+                            if (isSynthetic(one, two)) {
                                 toBeRemoved.add(one);
-                            } else if (two.isSynthetic() && 
!one.isSynthetic()) {
+                            } else if (isSynthetic(two, one)) {
                                 toBeRemoved.add(two);
                             }
                         }
                     } 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(two);
+                                toBeRemoved.add(isSynthetic(one, two) ? one : 
two);
                             } else if (oneDC.isInterface() ? (disjoint ? 
twoDC.implementsInterface(oneDC) : twoDC.isInterface()) : 
twoDC.isDerivedFrom(oneDC)) {
-                                toBeRemoved.add(one);
+                                toBeRemoved.add(isSynthetic(two, one) ? two : 
one);
                             }
                         }
                     }
@@ -1259,6 +1260,11 @@ public abstract class StaticTypeCheckingSupport {
         return (one.isDerivedFrom(two) || one.implementsInterface(two));
     }
 
+    private static boolean isSynthetic(final MethodNode one, final MethodNode 
two) {
+        return ((one.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0)
+            && ((two.getModifiers() & Opcodes.ACC_SYNTHETIC) == 0);
+    }
+
     /**
      * Given a receiver and a method node, parameterize the method arguments 
using
      * available generic type information.
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy 
b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 78a2311a99..99cdde9961 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -518,12 +518,14 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
-    // GROOVY-8638
+    // GROOVY-8638, GROOVY-10120
     void testReturnTypeInferenceWithMethodGenerics18() {
-        assertScript '''
+        String guava = '''
             @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()
@@ -533,6 +535,12 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
                 Collection<Integer> values = entry.value
             }
         '''
+
+        shouldFailWithMessages guava + '''
+            ListMultimap<String, Integer> mmap = ArrayListMultimap.create()
+            Map<String, Set<Integer>> map = mmap.asMap() // 
ArrayListMultimap#asMap() is bridge and lacks generics
+        ''',
+        '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-10222

Reply via email to