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

SC: map-style constructor call for non-static inner class within closure

    XMLWordPrintableJSON

Details

    Description

      Consider the following:

      @groovy.transform.CompileStatic
      class Foo {
        class Bar {
          def baz
        }
      
        void test() {
          { ->
            new Bar(baz: null)
          }.call()
        }
      }
      
      new Foo().test()
      

      The constructor call "new Bar(...)" produces an error at runtime:

      VerifyError: Bad type on operand stack
      Exception Details:
        Location:
          Foo$_test_closure1.doCall()LFoo$Bar; @5: invokespecial
        Reason:
          Type 'Foo$_test_closure1' (current frame, stack[2]) is not assignable to 'Foo'
        Current Frame:
          bci: @5
          flags: { }
          locals: { 'Foo$_test_closure1' }
          stack: { uninitialized 0, uninitialized 0, 'Foo$_test_closure1' }
      

      Remove the named argument or @CompileStatic and it runs fine.

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: