[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2022-03-24 Thread Paul King (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-10355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2022-03-24 Thread Jochen Theodorou (Jira)


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

Jochen Theodorou commented on GROOVY-10355:
---

ah... so it is thinking we want to cast _+ " C"_ to _b_ sorry, didn't get 
it correctly in the beginning if this would be the old parser I would try 
to give the binary expression higher priority. To have expression op expression 
be recognized properly in this case too, but is it right to do so? _(Integer) - 
myInt_ is probably an example that is supposed to work and not failing later by 
trying to subtract myInt from Integer. Even knowing which is a class and which 
is not may not help as long as _(A) + B_ is a valid case for example for a DSL.

> 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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2022-03-24 Thread Paul King (Jira)


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

Paul King commented on GROOVY-10355:


[~blackdrag] I am not sure I understand your question?
For the CST shown above for the {color:#4c9aff}*{{(b) + "C"}}*{color} case, we 
have: {color:#00875a}*{{expression => castParExpression expression}}*{color}.
For the AST we have:
!screenshot-2.png!

> 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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2022-03-24 Thread Jochen Theodorou (Jira)


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

Jochen Theodorou commented on GROOVY-10355:
---

[~daniel_sun] [~paulk] should a cast expression not consist of "expression 
(type)"? I am missing the expression in the front in the AST you have shown

> 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
>
>
> 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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2022-03-23 Thread Paul King (Jira)


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

Paul King commented on GROOVY-10355:


Looking at the CST in the groovyConsole gives:
 !screenshot-1.png! 

> 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
>
>
> 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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2022-03-23 Thread Eric Milles (Jira)


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

Eric Milles commented on GROOVY-10355:
--

[~olofasbrink] If you are using Groovy 3, you can still use the antlr2 parser 
if you are not using any of the new syntax features.  Otherwise, this is 
something that needs to be fixed in the antlr4 parser, which is not my area of 
expertise.

> 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
>
> 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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2022-03-23 Thread Olof Asbrink (Jira)


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

Olof Asbrink commented on GROOVY-10355:
---

[~emilles]  Any thoughts on if this is an easy fix and if it can be included in 
next micro releases? 

 

> 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
>
> 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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2022-01-10 Thread Olof Asbrink (Jira)


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

Olof Asbrink commented on GROOVY-10355:
---

This seems to happen using 4.0.0-rc-2 as well

 

> 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
> Environment: JDK 11.0.12
>Reporter: Olof Asbrink
>Priority: Major
>
> 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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2022-01-10 Thread Olof Asbrink (Jira)


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

Olof Asbrink commented on GROOVY-10355:
---

[~emilles] Do you know if this is addressed in 4.0.x and, if so, it's something 
that can be backported to 3.0.x?

 

> 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
> Environment: JDK 11.0.12
>Reporter: Olof Asbrink
>Priority: Major
>
> 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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2021-11-10 Thread Eric Milles (Jira)


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

Eric Milles commented on GROOVY-10355:
--

I think the parser sees "(b)" as a typecast expression.  "+ x" can be unary 
plus.  The precedence of binary +, typecast, and unary + don't appear to be 
respected here.

> 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
> Environment: JDK 11.0.12
>Reporter: Olof Asbrink
>Priority: Major
>
> 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)


[jira] [Commented] (GROOVY-10355) Compiler interpret variable name as class name when in parentheses.

2021-11-09 Thread Olof Asbrink (Jira)


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

Olof Asbrink commented on GROOVY-10355:
---

This is probably related to or a duplicate of:  GROOVY-9864

> 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
> Environment: JDK 11.0.12
>Reporter: Olof Asbrink
>Priority: Major
>
> 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)