Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
4.0.4
-
None
-
None
Description
Another problem with ternary operator, this time almost surely a clash with the safe index operator:
2034 ocs /tmp> >q.groovy 1>2?[1]:0 2035 ocs /tmp> /usr/local/groovy-4.0.4/bin/groovy q org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /private/tmp/q.groovy: 1: Unexpected input: ':' @ line 1, column 8. 1>2?[1]:0 ^ 1 error 2036 ocs /tmp>
Most probably affects 4 from the beginning. Used to work properly in previous versions (including Groovy 3 which supported the safe index operator all right).
The issue can be fixed easily e.g. inserting a space betwixt ? and [, thus the minor priority. Nevertheless it is somewhat inconvenient since the operation is pretty common and frequently occurs in the current codebase, which worked under 3 all right. Also, it is sort of difficult to solve it (semi-)automatically, for it is not entirely trivial to distinguish real safe indices from ternaries automatically without a full-fledged parser
Attachments
Issue Links
- is related to
-
GROOVY-9561 Some ternary expressions with []'s and 'as' are not parsed properly
- Open
-
GROOVY-10003 Eliminate some ambiguities while parsing
- Closed
- relates to
-
GROOVY-11509 Ternary Operator Spacing Issue
- Closed