Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9459

Line number information for automatically inserted return statements quirky

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.0
    • Fix Version/s: 4.0.0-alpha-1, 3.0.3
    • Component/s: None
    • Labels:
      None

      Description

      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.
       

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              vampire Björn Kautler
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: