[ 
https://issues.apache.org/jira/browse/GROOVY-11685?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17955443#comment-17955443
 ] 

ASF GitHub Bot commented on GROOVY-11685:
-----------------------------------------

Copilot commented on code in PR #2243:
URL: https://github.com/apache/groovy/pull/2243#discussion_r2118224734


##########
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java:
##########
@@ -2397,7 +2397,7 @@ public void visitReturnStatement(final ReturnStatement 
statement) {
 
     protected ClassNode checkReturnType(final ReturnStatement statement) {
         Expression expression = statement.getExpression();
-        ClassNode type = getType(expression);
+        var type = statement.isReturningNullOrVoid() ? VOID_TYPE : 
getType(expression); // GROOVY-11685

Review Comment:
   [nitpick] Consider using the explicit `ClassNode` type here instead of `var` 
to match the existing style and improve readability.
   ```suggestion
           ClassNode type = statement.isReturningNullOrVoid() ? VOID_TYPE : 
getType(expression); // GROOVY-11685
   ```



##########
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java:
##########
@@ -2419,7 +2419,8 @@ protected ClassNode checkReturnType(final ReturnStatement 
statement) {
                 } else if (statement.isReturningNullOrVoid() ? 
!isPrimitiveType(inferredReturnType) // GROOVY-7713, GROOVY-8202
                      : 
GenericsUtils.buildWildcardType(wrapTypeIfNecessary(inferredReturnType)).isCompatibleWith(wrapTypeIfNecessary(type)))
 {
                     type = inferredReturnType; // GROOVY-8310, GROOVY-10082, 
GROOVY-10091, GROOVY-10128, GROOVY-10306: allow simple covariance
-                } else if (!isPrimitiveVoid(type) && 
!extension.handleIncompatibleReturnType(statement, type)) { // GROOVY-10277: 
incompatible
+                } else if ((statement.isReturningNullOrVoid() || 
!isPrimitiveVoid(type)) && !extension.handleIncompatibleReturnType(statement, 
type)) {
+                    // GROOVY-10277, GROOVY-11490: incompatible return 
statement (null for primitive or inconvertible type)
                     String value = (statement.isReturningNullOrVoid() ? "null" 
: "value of type " + prettyPrintType(type));

Review Comment:
   [nitpick] This compound boolean condition is fairly complex; consider 
extracting `statement.isReturningNullOrVoid()` into a well-named boolean 
variable to clarify its intent.





> Static type checking fails with groovy 5.x
> ------------------------------------------
>
>                 Key: GROOVY-11685
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11685
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 5.0.0-beta-1
>            Reporter: Andriy Rysin
>            Assignee: Eric Milles
>            Priority: Major
>
> This project can compile and run under groovy-4 but fails static type 
> checking with groovy-5. I could not find what would be wrong with the code.
> [https://github.com/brown-uk/nlp_uk]
> {noformat}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> file:/home/user/nlp_uk/src/main/groovy/ua/net/nlp/tools/TextUtils.groovy: 
> 182: [Static type checking] - Cannot call 
> java.util.function.Consumer#call(capture-o
> f ? extends ua.net.nlp.tools.TextUtils.ResultBase) with arguments 
> [ua.net.nlp.tools.TextUtils$ResultBase]
>  @ line 182, column 6.
>                                         postProcessClosure(analyzed)
>         ^
> file:/home/user/nlp_uk/src/main/groovy/ua/net/nlp/tools/TextUtils.groovy: 
> 200: [Static type checking] - Cannot call 
> java.util.function.Consumer#call(capture-o
> f ? extends ua.net.nlp.tools.TextUtils.ResultBase) with arguments 
> [ua.net.nlp.tools.TextUtils$ResultBase]
>  @ line 200, column 4.
>                         postProcessClosure(analyzed)
>       ^
> file:/home/user/nlp_uk/src/main/groovy/ua/net/nlp/tools/tag/TagUnknown.groovy:
>  97: [Static type checking] - Incompatible generic argument types. Cannot 
> assign
>  java.util.List<java.lang.Object> to: 
> java.util.List<ua.net.nlp.tools.tag.TagTextCore.TaggedToken>
>  @ line 97, column 25.
>                retTokens = opToTagMap.collect { e ->
>                            ^
> file:/home/user/nlp_uk/src/main/groovy/ua/net/nlp/tools/tag/TagUnknown.groovy:
>  136: [Static type checking] - Incompatible generic argument types. Cannot 
> assig
> n java.util.List<? extends java.lang.Object> to: 
> java.util.List<ua.net.nlp.tools.tag.TagTextCore.TaggedToken>
>  @ line 136, column 16.
>            return retTokens
>                   ^
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to