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

Eric Milles edited comment on GROOVY-10796 at 10/25/22 9:03 PM:
----------------------------------------------------------------

In your original post, if you subtract "(defaults=false)", "def foo = new 
Foo(criteria: [fortyTwo: 42])" is implemented roughly as:
{code:groovy}
Foo tmp = new Foo()
tmp.setCriteria([fortyTwo: 42])
def foo = tmp
{code}


was (Author: emilles):
In your original post, if you subtract "(defaults=false)", "def foo = new 
Foo(criteria: [fortyTwo: 42])" is implemented roughly as:
{code:groovy}
def tmp = new Foo()
tmp.setCriteria([fortyTwo: 42])
def foo = tmp
{code}

> 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