@@ -850,7 +850,7 @@ && isAssignment(enclosingBinaryExpression.getOperation().getType())) {
850
850
&& !getOutermost (enclosingType ).equals (getOutermost (resultType ))
851
851
&& (Modifier .isPrivate (modifiers ) || !Objects .equals (enclosingType .getPackageName (), resultType .getPackageName ()))) {
852
852
resultType = originType ; // TODO: Find accesible type in hierarchy of resultType?
853
- } else if (GenericsUtils .hasUnresolvedGenerics (resultType )) {// GROOVY-9033, GROOVY-10089, et al.
853
+ } else if (GenericsUtils .hasUnresolvedGenerics (resultType )) { // GROOVY-9033, GROOVY-10089, et al.
854
854
Map <GenericsTypeName , GenericsType > enclosing = extractGenericsParameterMapOfThis (typeCheckingContext );
855
855
resultType = fullyResolveType (resultType , Optional .ofNullable (enclosing ).orElseGet (Collections ::emptyMap ));
856
856
}
@@ -2174,11 +2174,17 @@ protected ClassNode checkReturnType(final ReturnStatement statement) {
2174
2174
type = getType (expression );
2175
2175
}
2176
2176
if (typeCheckingContext .getEnclosingClosure () != null ) {
2177
+ ClassNode inferredReturnType = getInferredReturnType (typeCheckingContext .getEnclosingClosure ().getClosureExpression ());
2177
2178
// GROOVY-9995: return ctor call with diamond operator
2178
2179
if (expression instanceof ConstructorCallExpression ) {
2179
- ClassNode inferredClosureReturnType = getInferredReturnType (typeCheckingContext .getEnclosingClosure ().getClosureExpression ());
2180
- if (inferredClosureReturnType == null ) inferredClosureReturnType = DYNAMIC_TYPE ; // GROOVY-10080
2181
- inferDiamondType ((ConstructorCallExpression ) expression , inferredClosureReturnType );
2180
+ inferDiamondType ((ConstructorCallExpression ) expression , inferredReturnType != null ? inferredReturnType : /*GROOVY-10080:*/ DYNAMIC_TYPE );
2181
+ }
2182
+ if (STRING_TYPE .equals (inferredReturnType ) && isGStringOrGStringStringLUB (type )) {
2183
+ type = STRING_TYPE ; // GROOVY-9971: convert GString to String at point of return
2184
+ } else if (inferredReturnType != null && !inferredReturnType .isGenericsPlaceHolder ()
2185
+ && !type .isUsingGenerics () && !type .equals (inferredReturnType ) && (inferredReturnType .isInterface ()
2186
+ ? type .implementsInterface (inferredReturnType ) : type .isDerivedFrom (inferredReturnType ))) {
2187
+ type = inferredReturnType ; // GROOVY-10082: allow simple covariance
2182
2188
}
2183
2189
return type ;
2184
2190
}
@@ -2212,14 +2218,8 @@ protected ClassNode checkReturnType(final ReturnStatement statement) {
2212
2218
}
2213
2219
2214
2220
protected void addClosureReturnType (final ClassNode returnType ) {
2215
- TypeCheckingContext .EnclosingClosure enclosingClosure = typeCheckingContext .getEnclosingClosure ();
2216
- if (isGStringOrGStringStringLUB (returnType )
2217
- && STRING_TYPE .equals (getInferredReturnType (enclosingClosure .getClosureExpression ()))) {
2218
- // GROOVY-9971: convert GString to String at the point of return
2219
- enclosingClosure .addReturnType (STRING_TYPE );
2220
- } else if (!VOID_TYPE .equals (returnType )) {
2221
- enclosingClosure .addReturnType (returnType );
2222
- }
2221
+ if (returnType != null && !returnType .equals (VOID_TYPE )) // GROOVY-8202
2222
+ typeCheckingContext .getEnclosingClosure ().addReturnType (returnType );
2223
2223
}
2224
2224
2225
2225
@ Override
0 commit comments