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/22 16:21:42 UTC
[groovy] 01/02: 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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit fe84544d0b238e738e4e7f4db4de0cb8fa43e9be
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 18093b95f5..8a826212cc 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1712,7 +1712,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 dd92c842a4..b61d831a71 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 '''