You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2022/03/24 01:26:00 UTC

[jira] [Closed] (GROOVY-9864) Groovy 3 parsing error: surrounding a field name with parenthesis causes an "unable to resolve class error"

     [ https://issues.apache.org/jira/browse/GROOVY-9864?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-9864.
-----------------------------
    Resolution: Duplicate

Please see the explanation in GROOVY-10355. TL;DR: it is by design (currently). We could try to make later processing of the parsed AST smarter to pick out this case and adjust the AST but there are easy workarounds (in the meantime). 

> Groovy 3 parsing error: surrounding a field name with parenthesis causes an "unable to resolve class error"
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9864
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9864
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Howard
>            Priority: Major
>
> Hello,
> The follow code works on groovy 2 and does not work on groovy 3
> {code}
> class MyPartitioner implements Partitioner {
>     @Override
>     List<Map<String, String>> getPartition() {
>         final String ASDF = "a";
>         List<Map> lines = Arrays.asList(Map.of("a", "a"), Map.of("b", "b"));
>         List<Map> mapList = lines.collect {
>             Map map -> [(ASDF): (ASDF) + ""] as Map
>         }
>         return mapList;
>     }
> }
> public interface Partitioner {
>     List<Map<String, String>> getPartition();
> }
> new MyPartitioner().getPartition()
> {code}
> error msg
> {code}
> 1 compilation error:
> unable to resolve class ASDF
>  at line: 7, column: 33
> {code}
> The following lines are problematic
> {code}
> // the line below causes the unable to resolve class issue
>             Map map -> [(ASDF): (ASDF) + ""] as Map
> // by removing the parenthesis, it's gone
>             Map map -> [(ASDF): ASDF + ""] as Map
> // it's also gone if i remove the + ""
>             Map map -> [(ASDF): (ASDF)] as Map
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)