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

Implicit returns of transformed binary expressions do not have line numbers when statically compiled

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.7
    • Fix Version/s: 2.4.8
    • Component/s: Static compilation
    • Labels:
      None

      Description

      If certain transformed binary expressions (<=>, ==, <<, >>, >>>) are implicitly returned, their line numbers are not reported. Example:

      @groovy.transform.CompileStatic
      def test() {
          def l = []
          l << 3
      }
      

      The code above is compiled to the following bytecode (as seen using GroovyConsole):

        public test()Ljava/lang/Object;
         L0
          LINENUMBER 3 L0
          ICONST_0
          ANEWARRAY java/lang/Object
          INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.createList ([Ljava/lang/Object;)Ljava/util/List;
          ASTORE 1
         L1
          ALOAD 1
          POP
          ALOAD 1
          ICONST_3
          INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
          INVOKESTATIC org/codehaus/groovy/runtime/DefaultGroovyMethods.leftShift (Ljava/util/List;Ljava/lang/Object;)Ljava/util/List;
          ARETURN
         L2
          ACONST_NULL
          ARETURN
          LOCALVARIABLE this Lscript1466525199339; L0 L2 0
          LOCALVARIABLE l Ljava/util/List; L1 L2 1
          MAXSTACK = 2
          MAXLOCALS = 2
      

      There is no line number corresponding to L1, which includes the leftShift call (should be line number 4.)

      This is occurs because 1) BinaryExpressionTransformer does not copy the source position of the original expression to the transformed expression in some cases, and 2) ReturnAdder set the source position of the generated return for an expression statement with that of the expression.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                shils Shil Sinha
                Reporter:
                shils Shil Sinha
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: