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/08/12 18:33:13 UTC
[groovy] branch master updated: GROOVY-10120: STC: synthetic variant (bridge method) lacks generics info
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 f09ea218d6 GROOVY-10120: STC: synthetic variant (bridge method) lacks generics info
f09ea218d6 is described below
commit f09ea218d6bf0e03c6a4112b29b1ef67b16b501e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Aug 12 12:27:30 2022 -0500
GROOVY-10120: STC: synthetic variant (bridge method) lacks generics info
---
.../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 6ca999c1ab..1fcab91150 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1222,19 +1222,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);
}
}
}
@@ -1255,6 +1256,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 54ca029759..a22068beec 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