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

Eric Milles commented on GROOVY-10796:
--------------------------------------

If you use {{@TupleConstructor(defaults=false)}}, you stop the generation of a 
no-arg constructor, which is required for the "new Foo(criteria: [fortyTwo: 
42])" style.  You can add it back with {{@MapConstructor(noArg=true)}} or 
declare it yourself, in which case you'll probably need to add "force=true" to 
your tuple-constructor annotation.

> TupleConstructor and map-ish constructor style don't mix
> --------------------------------------------------------
>
>                 Key: GROOVY-10796
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10796
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Static compilation
>    Affects Versions: 4.0.6
>            Reporter: Christopher Smith
>            Priority: Major
>
> I'm not certain exactly where the semantic breakdown happens, but here's the 
> code setup:
> {code:groovy}
> @TupleConstructor(defaults = false)
> class Foo {
>   Map<String, Object> criteria
> }
> ...
> def foo = new Foo(criteria: [fortyTwo: 42])
> {code}
> I expect to have a {{Foo}} object whose {{criteria}} property contains the 
> mapping {{'fortyTwo'=42}}. Instead, I get a nested map:
> {code:groovy}
> assert [criteria: [fortyTwo: 42]] == foo.criteria
> {code}
> I know this has something to do with the map-constructor idiom (which I don't 
> use enough to be familiar with); instead, I expected the {{setCriteria}} 
> shorthand to be generated here. I get the sense that there's a gap in the 
> semantic definitions regarding "Map as the single constructor parameter".



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

Reply via email to