You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "OC (Jira)" <ji...@apache.org> on 2020/05/18 11:18:00 UTC
[jira] [Created] (GROOVY-9561) Some ternary expressions with []'s
and 'as' are not parsed properly
OC created GROOVY-9561:
--------------------------
Summary: Some ternary expressions with []'s and 'as' are not parsed properly
Key: GROOVY-9561
URL: https://issues.apache.org/jira/browse/GROOVY-9561
Project: Groovy
Issue Type: Bug
Components: parser
Affects Versions: 3.0.3
Reporter: OC
Expressions of type “1>2?[3] as Set:null” are not parsed properly, example below. I haven't tried all the versions, but I believe it is a problem caused by the parrot; I've checked 2.4.17 and 2.5.8 and both worked properly.
There's a very plain work-around, it suffices to enclose the middle part of the expression in parentheses, like “1>2?([3] as Set):null”. Besides, such expressions are pretty rare.
Far as I understand, the ambiguity of “as” and safe indexing both play their part and it might prove difficult to fix without forbidding “as” usage as identifier, which would break old code in a considerably worse way than this.
For all these reasons I believe the trivial priority in this case is better than minor, which would technically fit the problem better.
{code:java}
52 ocs /tmp> >q.groovy
1>2?[3] as Set:null
53 ocs /tmp> /usr/local/groovy-3.0.3/bin/groovy q
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/private/tmp/q.groovy: 1: Unexpected input: '1>2?[3]' @ line 1, column 1.
1>2?[3] as Set:null
^
1 error
54 ocs /tmp>
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)