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/03/30 19:46:35 UTC
[groovy] 03/03: GROOVY-9995: infer ctor call diamond type from closure target type
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit ebd46c4368bda4c4e87525013339aead42a48271
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Mar 22 12:27:23 2021 -0500
GROOVY-9995: infer ctor call diamond type from closure target type
---
.../codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
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 ba44773..f65bbbc 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1294,7 +1294,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
ClassNode leftRedirect = leftExpressionType.redirect();
// see if instanceof applies
if (rightExpression instanceof VariableExpression && hasInferredReturnType(rightExpression) && assignmentExpression.getOperation().getType() == EQUAL) {
- inferredRightExpressionType = rightExpression.getNodeMetaData(INFERRED_RETURN_TYPE);
+ inferredRightExpressionType = getInferredReturnType(rightExpression);
}
ClassNode wrappedRHS = adjustTypeForSpreading(inferredRightExpressionType, leftExpression);
@@ -2186,6 +2186,11 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
}
if (typeCheckingContext.getEnclosingClosure() != null) {
ClassNode inferredReturnType = getInferredReturnType(typeCheckingContext.getEnclosingClosure().getClosureExpression());
+ // GROOVY-9995: return ctor call with diamond operator
+ if (expression instanceof ConstructorCallExpression) {
+ ClassNode inferredClosureReturnType = getInferredReturnType(typeCheckingContext.getEnclosingClosure().getClosureExpression());
+ if (inferredClosureReturnType != null) inferDiamondType((ConstructorCallExpression) expression, inferredClosureReturnType);
+ }
if (inferredReturnType != null && inferredReturnType.equals(STRING_TYPE) && isGStringOrGStringStringLUB(type)) {
type = STRING_TYPE; // GROOVY-9971: convert GString to String at point of return
}