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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]