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


##########
src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java:
##########
@@ -285,17 +286,22 @@ private static void createConstructor(final 
AbstractASTTransformation xform, fin
                 tupleCtor.putNodeMetaData("_SKIPPABLE_ANNOTATIONS", 
Boolean.TRUE);
             }
             if (namedVariant) {
+                var pType = ClassHelper.MAP_TYPE.getPlainNodeReference();
+                // GROOVY-11644: check if named-param constructor would clash
+                if (cNode.getDeclaredConstructor(params(param(pType, "map"))) 
!= null

Review Comment:
   [nitpick] The inline array creation `params(param(pType, "map"))` is 
unclear. Consider extracting this to a variable with a descriptive name like 
`mapConstructorParams` for better readability.
   ```suggestion
                   var mapConstructorParams = params(param(pType, "map"));
                   if (cNode.getDeclaredConstructor(mapConstructorParams) != 
null
   ```



##########
src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java:
##########
@@ -285,17 +286,22 @@ private static void createConstructor(final 
AbstractASTTransformation xform, fin
                 tupleCtor.putNodeMetaData("_SKIPPABLE_ANNOTATIONS", 
Boolean.TRUE);
             }
             if (namedVariant) {
+                var pType = ClassHelper.MAP_TYPE.getPlainNodeReference();
+                // GROOVY-11644: check if named-param constructor would clash
+                if (cNode.getDeclaredConstructor(params(param(pType, "map"))) 
!= null
+                        || variants(signature).anyMatch(types -> types.length 
== 1 && types[0].equals(pType))) {
+                    xform.addError(String.format("%s(namedVariant=true) 
specifies duplicate constructor: %s(%s)",

Review Comment:
   [nitpick] The error message format string spans multiple lines making it 
harder to read. Consider using a StringBuilder or extracting the message to a 
constant for better maintainability.



-- 
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: notifications-unsubscr...@groovy.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to