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

Default Arguments: non-static inner class constructor call in default value not supported

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0-beta-1, 2.5.7
    • 3.0.0-beta-3, 2.5.13
    • None
    • None

    Description

      This is a variation of GROOVY-6777, GROOVY-6809 and GROOVY-7609.  A constructor's parameter may not presently be defaulted by a value expression using a non-static inner class (including anon. inner). This is likely caused by the uninitialized "this" reference that is supplied to the constructor of the non-static inner class.

      // Error: Apparent variable 'this' was found in a static scope but doesn't refer to a local variable, static field or class.
      class Outer {
        class Inner {} // make this static and all is well
        Outer(Inner inner = new Inner()) {
        }
      }
      new Outer()
      
      class C {
        C(Runnable runner = new Runnable() { void run() {} }) {
          //                ^^^^^^^^^^^^^^ enclosing method not set and ...
          this.runner = runner
        }
        Runnable runner
      }
      new C().runner.run()
      

      Attachments

        Issue Links

          Activity

            People

              daniel_sun Daniel Sun
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m