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/07/23 00:13:01 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-10699: STC: resolve type arguments from closure/lambda parameters
This is an automated email from the ASF dual-hosted git repository.
emilles 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 28c582afad GROOVY-10699: STC: resolve type arguments from closure/lambda parameters
28c582afad is described below
commit 28c582afad2d93b7ea55ef6b5af452c5683fc8d6
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Jul 22 09:37:03 2022 -0500
GROOVY-10699: STC: resolve type arguments from closure/lambda parameters
---
.../transform/stc/StaticTypeCheckingSupport.java | 2 +-
.../groovy/transform/stc/GenericsSTCTest.groovy | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
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 3e1d2b3c25..659c268baf 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1715,7 +1715,7 @@ public abstract class StaticTypeCheckingSupport {
* Should the target not have any generics this method does nothing.
*/
static void extractGenericsConnections(final Map<GenericsTypeName, GenericsType> connections, final ClassNode type, final ClassNode target) {
- if (target == null || target == type || !isUsingGenericsOrIsArrayUsingGenerics(target)) return;
+ if (target == null || target == type || (!target.isGenericsPlaceHolder() && !isUsingGenericsOrIsArrayUsingGenerics(target))) return;
if (type == null || type == UNKNOWN_PARAMETER_TYPE) return;
if (target.isGenericsPlaceHolder()) {
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index d7af6cbf8e..eaa5a038e1 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -3774,6 +3774,27 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-10699
+ void testReturnTypeInferenceWithClosure4() {
+ for (type in ['Function<T,T>', 'UnaryOperator<T>']) {
+ assertScript """import java.util.function.*
+
+ <T> T m($type x) {
+ x.apply(null)
+ }
+
+ void test() {
+ // the only type witness for T is the lambda parameter
+ @ASTTest(phase=INSTRUCTION_SELECTION, value={
+ assert node.getNodeMetaData(INFERRED_TYPE) == Double_TYPE
+ })
+ def x = m( (Double d) -> d ) // Expected type Object for lambda parameter: d
+ }
+ test()
+ """
+ }
+ }
+
// GROOVY-6129
void testShouldNotThrowNPE() {
assertScript '''