You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/10/10 21:12:00 UTC

[jira] [Updated] (GROOVY-5450) Final field assignment check on static compilation

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

Eric Milles updated GROOVY-5450:
--------------------------------
    Labels:   (was: contrib)

> 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
>            Assignee: Eric Milles
>            Priority: Major
>
> 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)