This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new acba27e047 GROOVY-8034: apply context type arguments to non-static
method parameter
acba27e047 is described below
commit acba27e047c529a4fe8b62824ae05d56ea799f43
Author: Eric Milles <[email protected]>
AuthorDate: Sun Sep 11 14:37:54 2022 -0500
GROOVY-8034: apply context type arguments to non-static method parameter
---
.../transform/stc/StaticTypeCheckingSupport.java | 9 +++++---
.../groovy/transform/stc/GenericsSTCTest.groovy | 27 +++++++++++++++++++++-
2 files changed, 32 insertions(+), 4 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 13508252a1..cbd3a2bf63 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1451,9 +1451,12 @@ public abstract class StaticTypeCheckingSupport {
}
static void addMethodLevelDeclaredGenerics(MethodNode method,
Map<GenericsTypeName, GenericsType> resolvedPlaceholders) {
- ClassNode dummy = OBJECT_TYPE.getPlainNodeReference();
- dummy.setGenericsTypes(method.getGenericsTypes());
- GenericsUtils.extractPlaceholders(dummy, resolvedPlaceholders);
+ GenericsType[] generics = method.getGenericsTypes();
+ if (!method.isStatic() && !resolvedPlaceholders.isEmpty()) {
+ // GROOVY-8034: non-static method may use class generics
+ generics = applyGenericsContext(resolvedPlaceholders, generics);
+ }
+
GenericsUtils.extractPlaceholders(GenericsUtils.makeClassSafe0(OBJECT_TYPE,
generics), resolvedPlaceholders);
}
protected static boolean typeCheckMethodsWithGenerics(ClassNode receiver,
ClassNode[] arguments, MethodNode candidateMethod) {
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 8ad3ffe3cc..e98192c633 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -2586,7 +2586,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
}
}
- void testCorrectlyBoundedBySuperGenericParameterType() {
+ void testCorrectlyBoundedBySuperGenericParameterType1() {
assertScript '''
class Foo {
static <T extends List<? super CharSequence>> void bar(T a) {}
@@ -2595,6 +2595,31 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase
{
'''
}
+ // GROOVY-8034
+ void testCorrectlyBoundedBySuperGenericParameterType2() {
+ assertScript '''
+ class A<I, O> {
+ def <IO extends A<? super O, ?>> IO andThen(IO next) { next }
+ }
+
+ def a1 = new A<String , Integer>()
+ def a2 = new A<Integer, Double >()
+ def a3 = new A<Double , String >()
+ def a4 = new A<String , Double >()
+ def a5 = new A<Number , Object >()
+
+ a1.andThen(a2)
+ a2.andThen(a3)
+ a3.andThen(a4)
+ a4.andThen(a5)
+
+ a1.andThen(a2)
+ .andThen(a3)
+ .andThen(a4)
+ .andThen(a5)
+ '''
+ }
+
void testCorrectlyBoundedByExtendsPlaceholderParameterType() {
assertScript '''
class Foo {