You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by "ocs@ocs.cz" <oc...@ocs.cz> on 2022/09/08 13:36:31 UTC

Groovy 4 parser bug?

Hi there,

I've just decided it's time to upgrade from Groovy 3 to Groovy 4... and immediately bumped into a problem, which looks like a parser bug in an extremely trivial scenario, which seems weird.

Do I perhaps miss something? I've checked https://groovy-lang.org/releasenotes/groovy-4.0.html#Groovy4.0-breaking, but in vain :(

===
2012 ocs /tmp> <q.groovy                            
def p
def x=p?[0]:[1]
println "got $x"
2013 ocs /tmp> /usr/local/groovy-3.0.12/bin/groovy q
got [1]
2014 ocs /tmp> /usr/local/groovy-4.0.4/bin/groovy q 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/private/tmp/q.groovy: 2: Unexpected input: ':' @ line 2, column 12.
   def x=p?[0]:[1]
              ^

1 error

2015 ocs /tmp> 
===

Thanks for any insight,
OC


Re: Groovy 4 parser bug?

Posted by "ocs@ocs.cz" <oc...@ocs.cz>.
P.S. Just in case someone else has the same problem — as I am playing with that, preliminarily it looks like the solution for a big codebase might be an ASTT which would list the positions of all the real safe indices; this ASTT would be run under Groovy 3 and its output would be then used with a script to automatically add spaces to all the ?['s which are not on the list.

Still, if Groovy 4.0.5 could fix the problem and parse this same way G3 did, it would be worlds easier :)

All the best,
OC

> On 9. 9. 2022, at 14:56, ocs@ocs.cz wrote:
> 
> Daniel,
> 
>> On 9. 9. 2022, at 1:30, Daniel Sun <su...@apache.org> wrote:
>> Add a space between ? and [
>> p ? [0] : [1]
> 
> Well thanks, but that really helps with new code only. On the other hand, with the existing codebase it is a royal PITA. Can't do that automatically, for I am afraid no regexp could reliably distinguish a real safe index from a ternary which returns a list or a map (actually, yesterday I've done this manually in one smaller project so that I can test Groovy 4 further — and even doing it manually I've made two mistakes of this kind).
> 
> All the best,
> OC
> 
>> On 2022/09/08 13:39:21 Christopher Smith wrote:
>>> The parser seems to be interpreting what you mean as a ternary as a
>>> null-safe array index.
>>> 
>>> On Thu, Sep 8, 2022, 08:37 ocs@ocs.cz <oc...@ocs.cz> wrote:
>>> 
>>>> Hi there,
>>>> 
>>>> I've just decided it's time to upgrade from Groovy 3 to Groovy 4... and
>>>> immediately bumped into a problem, which looks like a parser bug in an
>>>> extremely trivial scenario, which seems weird.
>>>> 
>>>> Do I perhaps miss something? I've checked
>>>> https://groovy-lang.org/releasenotes/groovy-4.0.html#Groovy4.0-breaking,
>>>> but in vain :(
>>>> 
>>>> ===
>>>> 2012 ocs /tmp> <q.groovy
>>>> def p
>>>> def x=p?[0]:[1]
>>>> println "got $x"
>>>> 2013 ocs /tmp> /usr/local/groovy-3.0.12/bin/groovy q
>>>> got [1]
>>>> 2014 ocs /tmp> /usr/local/groovy-4.0.4/bin/groovy q
>>>> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
>>>> failed:
>>>> /private/tmp/q.groovy: 2: Unexpected input: ':' @ line 2, column 12.
>>>>  def x=p?[0]:[1]
>>>>             ^
>>>> 
>>>> 1 error
>>>> 
>>>> 2015 ocs /tmp>
>>>> ===
>>>> 
>>>> Thanks for any insight,
>>>> OC
>>>> 
>>>> 
>>> 
> 


Re: Groovy 4 parser bug?

Posted by "ocs@ocs.cz" <oc...@ocs.cz>.
Daniel,

> On 9. 9. 2022, at 1:30, Daniel Sun <su...@apache.org> wrote:
> Add a space between ? and [
> p ? [0] : [1]

Well thanks, but that really helps with new code only. On the other hand, with the existing codebase it is a royal PITA. Can't do that automatically, for I am afraid no regexp could reliably distinguish a real safe index from a ternary which returns a list or a map (actually, yesterday I've done this manually in one smaller project so that I can test Groovy 4 further — and even doing it manually I've made two mistakes of this kind).

All the best,
OC

> On 2022/09/08 13:39:21 Christopher Smith wrote:
>> The parser seems to be interpreting what you mean as a ternary as a
>> null-safe array index.
>> 
>> On Thu, Sep 8, 2022, 08:37 ocs@ocs.cz <oc...@ocs.cz> wrote:
>> 
>>> Hi there,
>>> 
>>> I've just decided it's time to upgrade from Groovy 3 to Groovy 4... and
>>> immediately bumped into a problem, which looks like a parser bug in an
>>> extremely trivial scenario, which seems weird.
>>> 
>>> Do I perhaps miss something? I've checked
>>> https://groovy-lang.org/releasenotes/groovy-4.0.html#Groovy4.0-breaking,
>>> but in vain :(
>>> 
>>> ===
>>> 2012 ocs /tmp> <q.groovy
>>> def p
>>> def x=p?[0]:[1]
>>> println "got $x"
>>> 2013 ocs /tmp> /usr/local/groovy-3.0.12/bin/groovy q
>>> got [1]
>>> 2014 ocs /tmp> /usr/local/groovy-4.0.4/bin/groovy q
>>> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
>>> failed:
>>> /private/tmp/q.groovy: 2: Unexpected input: ':' @ line 2, column 12.
>>>   def x=p?[0]:[1]
>>>              ^
>>> 
>>> 1 error
>>> 
>>> 2015 ocs /tmp>
>>> ===
>>> 
>>> Thanks for any insight,
>>> OC
>>> 
>>> 
>> 


Re: Groovy 4 parser bug?

Posted by Daniel Sun <su...@apache.org>.
Add a space between ? and [

p ? [0] : [1]

Cheers,
Daniel Sun

On 2022/09/08 13:39:21 Christopher Smith wrote:
> The parser seems to be interpreting what you mean as a ternary as a
> null-safe array index.
> 
> On Thu, Sep 8, 2022, 08:37 ocs@ocs.cz <oc...@ocs.cz> wrote:
> 
> > Hi there,
> >
> > I've just decided it's time to upgrade from Groovy 3 to Groovy 4... and
> > immediately bumped into a problem, which looks like a parser bug in an
> > extremely trivial scenario, which seems weird.
> >
> > Do I perhaps miss something? I've checked
> > https://groovy-lang.org/releasenotes/groovy-4.0.html#Groovy4.0-breaking,
> > but in vain :(
> >
> > ===
> > 2012 ocs /tmp> <q.groovy
> > def p
> > def x=p?[0]:[1]
> > println "got $x"
> > 2013 ocs /tmp> /usr/local/groovy-3.0.12/bin/groovy q
> > got [1]
> > 2014 ocs /tmp> /usr/local/groovy-4.0.4/bin/groovy q
> > org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> > failed:
> > /private/tmp/q.groovy: 2: Unexpected input: ':' @ line 2, column 12.
> >    def x=p?[0]:[1]
> >               ^
> >
> > 1 error
> >
> > 2015 ocs /tmp>
> > ===
> >
> > Thanks for any insight,
> > OC
> >
> >
> 

Re: [EXT] Groovy 4 parser bug?

Posted by "ocs@ocs.cz" <oc...@ocs.cz>.
OK, thanks — https://issues.apache.org/jira/browse/GROOVY-10755 <https://issues.apache.org/jira/browse/GROOVY-10755>

All the best,
OC

> On 8. 9. 2022, at 16:13, Milles, Eric (TR Technology) via dev <de...@groovy.apache.org> wrote:
> 
> Best to open a new Jira ticket for this.  There were a number of scenarios that had to be handled for safe-indexing versus ternary expression.  Looks like there are still some out there.
>  
> Here is one example: https://issues.apache.org/jira/browse/GROOVY-9561 <https://issues.apache.org/jira/browse/GROOVY-9561>
>  
> https://issues.apache.org/jira/projects/GROOVY/issues <https://issues.apache.org/jira/projects/GROOVY/issues>
>  
> From: Christopher Smith <ch...@gmail.com> 
> Sent: Thursday, September 8, 2022 8:39 AM
> To: dev@groovy.apache.org
> Subject: [EXT] Re: Groovy 4 parser bug?
>  
> External Email: Use caution with links and attachments.
>  
> The parser seems to be interpreting what you mean as a ternary as a null-safe array index. 
>  
> On Thu, Sep 8, 2022, 08:37 ocs@ocs.cz <ma...@ocs.cz> <ocs@ocs.cz <ma...@ocs.cz>> wrote:
> Hi there,
> 
> I've just decided it's time to upgrade from Groovy 3 to Groovy 4... and immediately bumped into a problem, which looks like a parser bug in an extremely trivial scenario, which seems weird.
> 
> Do I perhaps miss something? I've checked https://groovy-lang.org/releasenotes/groovy-4.0.html#Groovy4.0-breaking <https://urldefense.com/v3/__https:/groovy-lang.org/releasenotes/groovy-4.0.html*Groovy4.0-breaking__;Iw!!GFN0sa3rsbfR8OLyAw!coZUfpDQb6wM7aQnB_qs22qgQ4Ua8PmHNoa6nVvXRqumFKTpcTU_ldwb5oy5T8UjVyNMjcdzN8FMNqOOlfcoBA$>, but in vain :(
> 
> ===
> 2012 ocs /tmp> <q.groovy                            
> def p
> def x=p?[0]:[1]
> println "got $x"
> 2013 ocs /tmp> /usr/local/groovy-3.0.12/bin/groovy q
> got [1]
> 2014 ocs /tmp> /usr/local/groovy-4.0.4/bin/groovy q 
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> /private/tmp/q.groovy: 2: Unexpected input: ':' @ line 2, column 12.
>    def x=p?[0]:[1]
>               ^
> 
> 1 error
> 
> 2015 ocs /tmp> 
> ===
> 
> Thanks for any insight,
> OC
> 


RE: [EXT] Re: Groovy 4 parser bug?

Posted by "Milles, Eric (TR Technology) via dev" <de...@groovy.apache.org>.
Best to open a new Jira ticket for this.  There were a number of scenarios that had to be handled for safe-indexing versus ternary expression.  Looks like there are still some out there.

Here is one example: https://issues.apache.org/jira/browse/GROOVY-9561

https://issues.apache.org/jira/projects/GROOVY/issues

From: Christopher Smith <ch...@gmail.com>
Sent: Thursday, September 8, 2022 8:39 AM
To: dev@groovy.apache.org
Subject: [EXT] Re: Groovy 4 parser bug?

External Email: Use caution with links and attachments.

The parser seems to be interpreting what you mean as a ternary as a null-safe array index.

On Thu, Sep 8, 2022, 08:37 ocs@ocs.cz<ma...@ocs.cz> <oc...@ocs.cz>> wrote:
Hi there,

I've just decided it's time to upgrade from Groovy 3 to Groovy 4... and immediately bumped into a problem, which looks like a parser bug in an extremely trivial scenario, which seems weird.

Do I perhaps miss something? I've checked https://groovy-lang.org/releasenotes/groovy-4.0.html#Groovy4.0-breaking<https://urldefense.com/v3/__https:/groovy-lang.org/releasenotes/groovy-4.0.html*Groovy4.0-breaking__;Iw!!GFN0sa3rsbfR8OLyAw!coZUfpDQb6wM7aQnB_qs22qgQ4Ua8PmHNoa6nVvXRqumFKTpcTU_ldwb5oy5T8UjVyNMjcdzN8FMNqOOlfcoBA$>, but in vain :(

===
2012 ocs /tmp> <q.groovy
def p
def x=p?[0]:[1]
println "got $x"
2013 ocs /tmp> /usr/local/groovy-3.0.12/bin/groovy q
got [1]
2014 ocs /tmp> /usr/local/groovy-4.0.4/bin/groovy q
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/private/tmp/q.groovy: 2: Unexpected input: ':' @ line 2, column 12.
   def x=p?[0]:[1]
              ^

1 error

2015 ocs /tmp>
===

Thanks for any insight,
OC

Re: Groovy 4 parser bug?

Posted by Christopher Smith <ch...@gmail.com>.
The parser seems to be interpreting what you mean as a ternary as a
null-safe array index.

On Thu, Sep 8, 2022, 08:37 ocs@ocs.cz <oc...@ocs.cz> wrote:

> Hi there,
>
> I've just decided it's time to upgrade from Groovy 3 to Groovy 4... and
> immediately bumped into a problem, which looks like a parser bug in an
> extremely trivial scenario, which seems weird.
>
> Do I perhaps miss something? I've checked
> https://groovy-lang.org/releasenotes/groovy-4.0.html#Groovy4.0-breaking,
> but in vain :(
>
> ===
> 2012 ocs /tmp> <q.groovy
> def p
> def x=p?[0]:[1]
> println "got $x"
> 2013 ocs /tmp> /usr/local/groovy-3.0.12/bin/groovy q
> got [1]
> 2014 ocs /tmp> /usr/local/groovy-4.0.4/bin/groovy q
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> /private/tmp/q.groovy: 2: Unexpected input: ':' @ line 2, column 12.
>    def x=p?[0]:[1]
>               ^
>
> 1 error
>
> 2015 ocs /tmp>
> ===
>
> Thanks for any insight,
> OC
>
>