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

Cannot set protected field from subclass

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.6
    • 3.0.0-beta-2, 2.5.19
    • None
    • None

    Description

      Consider the following code

      @CompileStatic
      abstract class Foo {
      
          protected String field1
      
          String getField1() {
              field1
          }
      }
      
      @CompileStatic
      class Bar extends Foo {
      
          void changeField1()  {
              this.field1 = 'foo'
          }
      
          @Override
          String getField1() { return 'bar command' }
      }
      

      It fails to compile with the following error message:

      [Static type checking] - Cannot set read-only property: field1
       @ line 29, column 9.
                 this.field1 = 'foo'
                 ^
      

      Which does not make much sense to me because protected field should be accessible to subclasses by definition. Tested also with 2.5.8-SNAPSHOT reporting the same issue.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              pablo72 paolo di tommaso
              Votes:
              0 Vote for this issue
              Watchers:
              3 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
                  1h