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 2022/02/03 22:33:01 UTC

[jira] [Closed] (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 ]

Paul King closed GROOVY-5450.
-----------------------------

> 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
>             Fix For: 4.0.0-beta-2
>
>
> 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.20.1#820001)