Björn Kautler created GROOVY-9459:
-------------------------------------

             Summary: Line number information for automatically inserted return 
statements quirky
                 Key: GROOVY-9459
                 URL: https://issues.apache.org/jira/browse/GROOVY-9459
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 3.0.0
            Reporter: Björn Kautler


While trying to work-around GROOVY-9440, I found another quirk regarding line 
numbers.
I'm sorry if this is intended and not a bug, but it looks strange to me.

Here what I found out so far:

 

The Spock AST transformation previously had (semantically equivalent) {{new 
ReturnStatement(new ExpressionStatement(theVariableExpression)))}} where the 
two statements have no line information, the expression does have it.
This caused the line information to be missing from the 
{{MissingPropertyException}}.
If I look at the AST Browser at end of semantic analysis, this results in 
{{ReturnStatement -> Variable}} where the return statement has no line 
information, the variable does have it, in both 2.5.8 and 3.0.0.
 
I thought as work-around I remove the explicit return statement and let Groovy 
handle it, as it knows better what to do, so currently I have {{new 
ExpressionStatement(theVariableExpression))}} where the statement still has no 
line information, but the expression does have it.
This now causes the line information to be missing from the 
{{MissingPropertyException}} still, if Groovy 3.0.0 is used.
If I look at the AST Browser at end of semantic analysis, this results in 
{{ExpressionStatement -> Variable}} where the statement has no line 
information, the variable does have it, in both 2.5.8 and 3.0.0.
If I now look at the end of class generation, this results in {{ReturnStatement 
-> Variable}} in both 2.5.8 and 3.0.0, but only 2.5.8 has line information for 
the return statement, in 3.0.0 it is {{-1}}.
 
I now tried {{ExpressionStatement exprStat = new 
ExpressionStatement(theVariableExpression)); exprStat.setLineNumber(666);}} and 
now it gets even fancier.
In 2.5.8 the return statement takes the line information from the variable 
expression, ignoring the expression statement,
in 3.0.0 the return statement takes the line information from the expression 
statement.
 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to