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/09/14 19:34:56 UTC
[groovy] branch GROOVY_3_0_X 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 GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new c3454a04b9 GROOVY-10120: STC: synthetic variant (bridge method) lacks generics info
c3454a04b9 is described below
commit c3454a04b94e7af4f6a0830b14592fe1095a7b8b
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
3_0_X backport
---
.../transform/stc/StaticTypeCheckingSupport.java | 20 ++++++++++++--------
src/test/groovy/transform/stc/GenericsSTCTest.groovy | 12 ++++++++++--
2 files changed, 22 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 e2e33aa2f8..c441658693 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1196,21 +1196,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
- if (twoDC.isInterface() ? oneDC.implementsInterface(twoDC)
- : oneDC.isDerivedFrom(twoDC)) {
- toBeRemoved.add(two);
- } else if (oneDC.isInterface() ? twoDC.isInterface()
- : twoDC.isDerivedFrom(oneDC)) {
- toBeRemoved.add(one);
+ // 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);
+ } else if (oneDC.isInterface() ? twoDC.isInterface() : twoDC.isDerivedFrom(oneDC)) {
+ toBeRemoved.add(isSynthetic(two, one) ? two : one);
}
}
}
@@ -1231,6 +1230,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 a68c732f7f..eb308f3b23 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -529,12 +529,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()
@@ -544,6 +546,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 <String, java.util.Collection> to: java.util.Map <String, Set>'
}
// GROOVY-10222