You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2019/07/22 04:22:02 UTC

[jira] [Closed] (GROOVY-9127) Cannot set protected field from subclass

     [ https://issues.apache.org/jira/browse/GROOVY-9127?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-9127.
-----------------------------

> Cannot set protected field from subclass
> ----------------------------------------
>
>                 Key: GROOVY-9127
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9127
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.6
>            Reporter: paolo di tommaso
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 3.0.0-beta-2
>
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> Consider the following code 
> {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' }
> }
> {code}
> It fails to compile with the following error message: 
> {code}
> [Static type checking] - Cannot set read-only property: field1
>  @ line 29, column 9.
>            this.field1 = 'foo'
>            ^
> {code}
> 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.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)