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 2025/04/17 05:26:00 UTC
[jira] [Commented] (GROOVY-10724) Parrot parser incorrectly treats an expression wrapped in parentheses as a cast
[ https://issues.apache.org/jira/browse/GROOVY-10724?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17945229#comment-17945229 ]
Paul King commented on GROOVY-10724:
------------------------------------
Workarounds for: (a) in [2, 3, 4]
{code:groovy}
def b2 = a in [2, 3, 4]
def b3 = ((a)) in [2, 3, 4]
def b4 = [2, 3, 4].isCase(a)
def b5 = [2, 3, 4].isCase((a))
def b6 = [2, 3, 4].contains(a)
def b7 = [2, 3, 4].contains((a))
assert [b2, b3, b4, b5, b6, b7].every()
{code}
Workarounds for: (a) as Integer
{code:groovy}
def c2 = a as Integer
def c3 = ((a)) as Integer
def c4 = (a).asType(Integer)
def c5 = (Integer)(a)
[c2, c3, c4, c5].every { assert it == 3 }
{code}
Workarounds for: (a) +2 // unary plus
{code:groovy}
def d2 = a +2
def d3 = ((a)) +2
def d4 = (a).plus(2)
[d2, d3, d4].every { assert it == 5 }
{code}
Workarounds for: (a) -1 // unary minus
{code:groovy}
def e2 = a -1
def e3 = ((a)) -1
def e4 = (a).minus(2)
[e2, e3, e4].every { assert it == 2 }
{code}
> Parrot parser incorrectly treats an expression wrapped in parentheses as a cast
> -------------------------------------------------------------------------------
>
> Key: GROOVY-10724
> URL: https://issues.apache.org/jira/browse/GROOVY-10724
> Project: Groovy
> Issue Type: Bug
> Components: parser-antlr4
> Affects Versions: 3.0.12
> Reporter: Marcin Erdmann
> Priority: Major
>
> Trying to compile this code:
> {code:java}
> def a = ""
> (a) in []
> {code}
> results in
> {code:java}
> /path/to/file/Foo.groovy: 10: unable to resolve class a
> @ line 21, column 9.
> (a) in []
> ^
> 1 error
> {code}
> Obviously the parentheses are not necessary and the problem goes away if you drop them but it would be good if that code was still allowed like it was in 2.5 or if at least the error wasn't so confusing.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)