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

Paul King commented on GROOVY-10355:
------------------------------------

Yes, the old parser has hard-coded built in types:
{noformat}
builtInType
: "void" | "boolean" | "byte" | "char" | "short" | "int" | "float" | "long" | 
"double"
{noformat}
So "(long)-3" is handled as a special case and non built-in types default back 
to binary expressions, so for instance "(Long)-3" isn't handled but the above 
"(b) + 'C'" case would have been fine. The new parser tries to be more 
consistent so that "(long)-3" (primitive type) and "(Long)-3" (wrapper type) 
are treated the same way for example. Whether we could be smarter and try to 
transform the AST at a later stage to reconstitute it back into a binary 
expression is difficult to say. In theory we could look for identifiers which 
are in scope or identifiers which aren't resolved but it would likely be messy. 
Given that there are easy workarounds, I am unsure if it is worth pursuing.

> Compiler interpret variable name  as class name when in parentheses.
> --------------------------------------------------------------------
>
>                 Key: GROOVY-10355
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10355
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.8, 4.0.0-rc-2
>         Environment: JDK 11.0.12
>            Reporter: Olof Asbrink
>            Priority: Major
>         Attachments: screenshot-1.png, screenshot-2.png
>
>
> This behavior seems unexpected:
> {code:java}
> String b = "B"
> System.out.println("A" + (b) + "C")
> {code}
> Throws this exception:
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> /tmp/repo1.gm: 2: unable to resolve class b
>  @ line 2, column 26.
>    System.out.println("A" + (b) + "C")
>                             ^{code}
> However these examples work:
> {code:java}
> String b = "B"
> System.out.println("A" + b + "C")
> {code}
> and
> {code:java}
> String b = "B"
> System.out.println("A" + (b))
> {code}



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

Reply via email to