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 acd1a7af9f4..36b082ffd10 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -279,7 +279,6 @@ import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findDGMMethodsForClassNode; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findSetters; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findTargetVariable; -import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.fullyResolve; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.fullyResolveType; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCombinedBoundType; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCombinedGenericsType; @@ -2945,10 +2944,9 @@ protected void visitMethodCallArguments(final ClassNode receiver, final Argument if (i > 0 || !(selectedMethod instanceof ExtensionMethodNode)) { inferClosureParameterTypes(receiver, arguments, source, target, selectedMethod); } - if (isFunctionalInterface(targetType)) { - storeInferredReturnType(source, GenericsUtils.parameterizeSAM(targetType).getV2()); - } else if (isClosureWithType(targetType)) { - storeInferredReturnType(source, getCombinedBoundType(targetType.getGenericsTypes()[0])); + if (isClosureWithType(targetType)) { + ClassNode returnType = getCombinedBoundType(targetType.getGenericsTypes()[0]); + storeInferredReturnType(source, returnType); } } expression.visit(this); @@ -3132,10 +3130,8 @@ protected void inferClosureParameterTypes(final ClassNode receiver, final Expres }); } - for (GenericsType tp : typeParameters) { - GenericsTypeName name = new GenericsTypeName(tp.getName()); - context.computeIfAbsent(name, x -> fullyResolve(tp, context)); - } + // GROOVY-8917, GROOVY-10049, GROOVY-11414, et al. + stubMissingTypeVariables(typeParameters, context); } } diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy index 909928391b9..f99c6f90453 100644 --- a/src/test/groovy/transform/stc/LambdaTest.groovy +++ b/src/test/groovy/transform/stc/LambdaTest.groovy @@ -88,6 +88,16 @@ final class LambdaTest { ''' } + // GROOVY-11414 + @Test + void testFunction5() { + def err = shouldFail shell, ''' + def map = (Map) [:] + map.computeIfAbsent('key', (k) -> 1) + ''' + assert err =~ /Cannot return value of type int for lambda expecting java.lang.Long/ + } + @Test void testBinaryOperator() { assertScript shell, '''