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

Christopher Smith commented on GROOVY-10796:
--------------------------------------------

I think the (bad-)surprising part to me is that I did not expect a list of 
{{name: value}} inside the constructor call that was not enclosed in brackets 
to be wrapped up into a {{Map}} in the absence of a {{MapConstructor}}. I'm 
also aware that there may be an unavoidable structural ambiguity with 
{{MapConstructor}} and "other constructor that takes a single {{Map}} as a 
parameter". Essentially, it seems that there are multiple separate language 
features that make conflicting inferences based on the presence of exactly 
{{<init>(Map)}}. Is this the essence of the problem?

> 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