This is an automated email from the ASF dual-hosted git repository.
sunlan 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 95e2871da9 GROOVY-11683: STC: transfer generics to extension method
return types (#2253)
95e2871da9 is described below
commit 95e2871da954d96d6f08915b9ba6cb7fa26a9a87
Author: Eric Milles <[email protected]>
AuthorDate: Fri Jun 13 19:11:49 2025 -0500
GROOVY-11683: STC: transfer generics to extension method return types
(#2253)
---
.../transform/stc/StaticTypeCheckingVisitor.java | 5 ++--
.../transform/stc/MethodReferenceTest.groovy | 31 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 2f2e7e185e..218529fa53 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2675,7 +2675,7 @@ out: if ((samParameterTypes.length == 1 &&
isOrImplements(samParameterTypes[0
if (!candidates.isEmpty()) {
ClassNode[] arguments =
expression.getNodeMetaData(CLOSURE_ARGUMENTS);
- if (asBoolean(arguments) &&
asBoolean(receiverType.redirect().getGenericsTypes())
+ if (asBoolean(arguments) && missesGenericsTypes(receiverType)
// GROOVY-10984
&& expression.getExpression()
instanceof ClassExpression) {
receiverType =
GenericsUtils.parameterizeType(arguments[0], receiverType); // GROOVY-11241
}
@@ -2685,7 +2685,8 @@ out: if ((samParameterTypes.length == 1 &&
isOrImplements(samParameterTypes[0
.peek(candidate ->
checkOrMarkPrivateAccess(expression, candidate)) // GROOVY-11365
.map (candidate -> {
ClassNode returnType = candidate.getReturnType();
- if (!candidate.isStatic() &&
GenericsUtils.hasUnresolvedGenerics(returnType)) {
+ if (!isStaticInContext(candidate) // GROOVY-11683
+ &&
GenericsUtils.hasUnresolvedGenerics(returnType)) {
Map<GenericsTypeName, GenericsType> spec = new
HashMap<>(); // GROOVY-11364
extractGenericsConnections(spec, ownerType,
candidate.getDeclaringClass());
returnType = applyGenericsContext(spec,
returnType);
diff --git a/src/test/groovy/groovy/transform/stc/MethodReferenceTest.groovy
b/src/test/groovy/groovy/transform/stc/MethodReferenceTest.groovy
index a622e579aa..18f54655a9 100644
--- a/src/test/groovy/groovy/transform/stc/MethodReferenceTest.groovy
+++ b/src/test/groovy/groovy/transform/stc/MethodReferenceTest.groovy
@@ -1347,6 +1347,37 @@ final class MethodReferenceTest {
'''
}
+ // GROOVY-11683
+ @Test // class::instanceGroovyMethod
+ void testFunctionCI_DGM2() {
+ String head = '''\
+ import static org.codehaus.groovy.control.CompilePhase.*
+ import static org.codehaus.groovy.transform.stc.StaticTypesMarker.*
+
+ @CompileStatic
+ void test(Iterable<String> iterable) {
+ @ASTTest(phase=INSTRUCTION_SELECTION, value={
+ Object type = node.getNodeMetaData(INFERRED_TYPE)
+ assert type.toString(false) ==
'java.util.Optional<java.util.Collection<java.lang.String>>'
+ })
+ '''
+ String tail = '''\
+ }
+
+ test()
+ '''
+
+ assertScript shell, head + '''
+ def optional =
Optional.ofNullable(iterable).map(Iterable::asCollection)
+ assert optional.isEmpty()
+ ''' + tail
+
+ assertScript shell, head + '''
+ def optional = Optional.empty().map(Iterable<String>::asCollection)
+ assert optional.isEmpty()
+ ''' + tail
+ }
+
@Test // class::staticGroovyMethod
void testFunctionCS_DGSM() {
assertScript shell, '''