[
https://issues.apache.org/jira/browse/GROOVY-11644?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18007295#comment-18007295
]
ASF GitHub Bot commented on GROOVY-11644:
-----------------------------------------
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.
> Record classes with a map parameter cause errors with duplicate map
> constructors
> --------------------------------------------------------------------------------
>
> Key: GROOVY-11644
> URL: https://issues.apache.org/jira/browse/GROOVY-11644
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 5.0.0-alpha-12
> Reporter: Saravanan
> Assignee: Eric Milles
> Priority: Minor
>
> Records that have a map field with static compilation enabled will produce
> this error
>
> {code:java}
> // The constructor public void <init>(java.util.Map __namedArgs) { ...
> }duplicates another constructor of the same signature
> record AttributeRules(Map<String, List<Integer>> ruleIDs) {
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)