You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/06/17 15:27:00 UTC
[jira] [Commented] (GROOVY-10659) Using map literal as function argument, does not compile.
[ https://issues.apache.org/jira/browse/GROOVY-10659?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17555661#comment-17555661 ]
Eric Milles commented on GROOVY-10659:
--------------------------------------
For a non-string, non-integer key, you need to surround the key expression in parentheses.
> Using map literal as function argument, does not compile.
> ---------------------------------------------------------
>
> Key: GROOVY-10659
> URL: https://issues.apache.org/jira/browse/GROOVY-10659
> Project: Groovy
> Issue Type: Bug
> Reporter: Michal Ševčenko
> Priority: Major
>
> This is IMO a regression (wrt. e.g. Groovy 2.4.11), the following does not compile in Groovy 3.0.10.
> {code:java}
> def fun = { arg ->
> return arg
> }
> fun (
> x: 1,
> [a: 1]: '2'
> ){code}
> This is the combination of the following:
> * map literal is used as an argument of a function, without enclosing brackets (I hope this is legal)
> * another map literal is used as a key of the outer map (I hope this is legal too)
> If both these preconditions are met, the compiler complains with:
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> index.groovy: 5: Unexpected input: '(' @ line 5, column 5.
> fun (
> ^
> 1 error {code}
> This does compile:
> {code:java}
> def fun = { arg ->
> return arg
> }
> fun (
> x: 1,
> a: '2'
> ){code}
> So does this:
> {code:java}
> def fun = { arg ->
> return arg
> }
> fun ([
> x: 1,
> [a: 1]: '2'
> ]) {code}
> Is this a bug?
--
This message was sent by Atlassian Jira
(v8.20.7#820007)