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

Can't access static method from same class within this constructor call

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.6.0-alpha-1, 3.0.0-alpha-3, 2.5.2
    • Fix Version/s: 3.0.0-alpha-4, 2.5.3
    • Component/s: None
    • Labels:
      None
    • Environment:
      groovc command line on linux

      Description

      The parser in 2.5, 2.6, 3.0 gives a MultipleCompilationErrorsException on code that compiled successfully in 2.4

      Code that fails to compile on 2.6.0-alpha-1
      class A {
          static String g() { }
          A() {
              this({g()}) // It is ok to create a closure that calls g() in a constructor, but not if it is being passed into this().
          }
          A(a) { }
      }
      
      compilation error message
      $ groovyc test.groovy  
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 4: Can't access instance method 'g' before the class is constructed
       @ line 4, column 15.
                 this({g()}) // It is ok to create a closure that calls g() in a constructor, but not if it is being passed into this().
                       ^
      
      1 error
      

      My opinion is that groovy should allow users to call a static method inside a constructor before the instance has been fully constructed, but I'm not aware of the details of why this is disallowed in 2.6.0-alpha-1.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                daniel_sun Daniel Sun
                Reporter:
                idooley Isaac Dooley
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: