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

Cannot call private constructor error - @CompileStatic & default method argument

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.7, 2.4.10
    • 2.4.13
    • Static compilation
    • None

    Description

      Groovy compiler reports error on a try of use private constructor with default method argument from a static method:
      Error:(15, 16) Groovyc: Cannot call private constructor for com.ofg.test.CannotCallPrivateConstructorIssueReproductor from class com.ofg.test.CannotCallPrivateConstructorIssueReproductor

      Sample code to reproduce that issue:

      @CompileStatic
      class CannotCallPrivateConstructorIssueReproductor {
      
          private final String someFiled //final is NOT mandatory to reproduce the issue
      
          private CannotCallPrivateConstructorIssueReproductor(String someFiled, Integer optionalArgument = null) {   //field with default value is crutial
              this.someFiled = someFiled
          }
      
          static CannotCallPrivateConstructorIssueReproductor factoryMethod() {
              return new CannotCallPrivateConstructorIssueReproductor('sth')
          }
      }
      

      Tested with Groovy 2.4.7 and 2.4.10

      Attachments

        Activity

          People

            paulk Paul King
            szpak Marcin Zajaczkowski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: