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

CompileStatic: Cannot set default-visible property in superclass that has a getter without a setter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0.17
    • 3.0.18
    • Compiler
    • None

    Description

      If a class's ancestors declare a default-visibility property and a getter for that property:

      class HasProperty {
          Object foo
      
          Object getFoo() {
             return foo
          }
      } 

      Then the class, if it is CompileStatic, cannot set that property.

       

      This fails to compile:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class SetsProperty extends HasProperty {
          void doStuff() {
             foo = "example"
          }
      } 

      Compiler output:

      SetsProperty.groovy: 8: [Static type checking] - Cannot set read-only property: foo
       @ line 8, column 3.
                 foo = "example"

       

      It also fails to compile with "this.@":

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class SetsProperty extends HasProperty {
          void doStuff() {
             this.@foo = "example"
          }
      } 

      Results in:

      SetsProperty.groovy: 8: [Static type checking] - The field HasProperty.foo is not accessible
       @ line 8, column 9.
                 this.@foo = "example"

       

      These do compile if the class is not CompileStatic, or if the property is explicitly declared "public".

       

       

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              jasongarrett Jason Garrett
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: