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

Paul King updated GROOVY-5450:
------------------------------
    Description: 
The following class definition should generate a compilation error on final 
field assignment.
{code}
@groovy.transform.CompileStatic
class StaticGroovy3 {
    def testFinalField() {
        def ff = new FinalField()
        ff.aField = 'y'
        println ff
    }
}

class FinalField {
    final aField = 'x'
}

new StaticGroovy3().testFinalField()
{code}
Fails at runtime with {{groovy.lang.ReadOnlyPropertyException: Cannot set 
readonly property: aField for class: FinalField}}

  was:
The following class definition should generate a compilation error on final 
field assignment.
{code}
@CompileStatic
class StaticGroovy3 {
    def testFinalField() {
        new FinalField().aField = ""
    }
}

class FinalField {
    final aField;
} 
{code}


> Final field assignment check on static compilation
> --------------------------------------------------
>
>                 Key: GROOVY-5450
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5450
>             Project: Groovy
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 2.0-beta-3
>            Reporter: Renato Garcia
>            Priority: Major
>              Labels: contrib
>
> The following class definition should generate a compilation error on final 
> field assignment.
> {code}
> @groovy.transform.CompileStatic
> class StaticGroovy3 {
>     def testFinalField() {
>         def ff = new FinalField()
>         ff.aField = 'y'
>         println ff
>     }
> }
> class FinalField {
>     final aField = 'x'
> }
> new StaticGroovy3().testFinalField()
> {code}
> Fails at runtime with {{groovy.lang.ReadOnlyPropertyException: Cannot set 
> readonly property: aField for class: FinalField}}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to