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

Class.this not evaluated correctly within a closure within an inner class

    XMLWordPrintableJSON

    Details

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

      Description

      There is an incorrect calculation of a qualified 'this' within a closure within an inner class:

      //@groovy.transform.CompileStatic
      class Test {
        def op1() { this }
        def op2() { ''.with{ this } }
        def op3() { new Object() { def inner() { this } } }
        def op4() { new Object() { def inner() { ''.with{ this } } } }
        def op5() { new Object() { def inner() { Test.this } } }
        def op6() { new Object() { def inner() { ''.with{ Test.this } } } }
        class Inner {
          def inner1() { this }
          def inner2() { ''.with { this } }
          def inner3() { Test.this }
          def inner4() { ''.with { Test.this } }
        }
      }
      
      def t = new Test()
      assert t.op1().class.name == 'Test'
      assert t.op2().class.name == 'Test'
      assert t.op3().inner().class.name == 'Test$1'
      assert t.op4().inner().class.name == 'Test$2'
      assert t.op5().inner().class.name == 'Test'
      assert t.op6().inner().class.name == 'Test$4$_inner_closure1'  // Current
      //assert t.op6().inner().class.name == 'Test'  // Expected
      
      def inner = new Test.Inner(t)
      assert inner.inner1().class.name == 'Test$Inner'
      assert inner.inner2().class.name == 'Test$Inner'
      assert inner.inner3().class.name == 'Test'
      assert inner.inner4().class.name == 'Test$Inner$_inner4_closure2' // Current
      // assert inner.inner4().class.name == 'Test' // Expected
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                paulk Paul King
                Reporter:
                paulk Paul King
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: