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

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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.7, 2.4.10
    • Fix Version/s: 2.4.13
    • Component/s: Static compilation
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: