You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Pontus (JIRA)" <ji...@apache.org> on 2018/08/08 11:26:00 UTC

[jira] [Created] (GROOVY-8734) Using 'var' in operation followed by comment fails compilation

Pontus created GROOVY-8734:
------------------------------

             Summary: Using 'var' in operation followed by comment fails compilation
                 Key: GROOVY-8734
                 URL: https://issues.apache.org/jira/browse/GROOVY-8734
             Project: Groovy
          Issue Type: Bug
          Components: lexer
    Affects Versions: 3.0.0-alpha-3
         Environment: Windows, Java 1.8.0_152
            Reporter: Pontus


There seems to be some issue with scripting containing variables called "var" and then followed by a comment.

This crashes with MultipleCompilationErrorsException (unexpected input 'return'):
{code:java}
def a = var / 10
// return bla
return a{code}
This crashes with MissingPropertyException (not found: foo):
{code:java}
def a = foo / 10
// return bla
return a
{code}
This crashes with MissingPropertyException (not found: var):
{code:java}
def a = var / 10
return a
{code}
This crashes with MissingPropertyException (not found: What):

 
{code:java}
def a = var / 10
// What is happening
return a
{code}
 

Works:
{code:java}
def var = 10
def a = var / 10
return a
{code}
This crashes with MultipleCompilationErrorsException (Unexpected input: '?')
{code:java}
def var = 10
def a = var / 10
// What?
return a
{code}
Works:
{noformat}
def foo = 10
def a = foo / 10
// What?
return a{noformat}
I did not know that "var" was handled by Groovy. But anyway, seems something is quite off with it. We noticed this after upgrading from Groovy 2.x to 3, where the script used to work in 2.x.

I can see in the lexer that the tokens that are recognized become really weird, with everything between "var / [..] /" becomes one token, then "/ return" fails since you of course cannot divide by 'return'.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)