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 2020/02/26 11:25:00 UTC

[jira] [Commented] (GROOVY-9424) Handling of final variables

    [ https://issues.apache.org/jira/browse/GROOVY-9424?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17045402#comment-17045402 ] 

Paul King commented on GROOVY-9424:
-----------------------------------

This looks like a bug in the final variable analyzer.

> Handling of final variables
> ---------------------------
>
>                 Key: GROOVY-9424
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9424
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Daniel Wilmer
>            Priority: Major
>
> The following code runs on groovy 2.4.18 but not on groovy 3.0.1.
> {code}
> static void main(String[] args) {
>     final String result
>     switch (2) {
>         case 1: result = "a"; break;
>         case 2: result = "b"; break;
>         default: result = "x"
>     }
>     println result
> }
> {code}
> *Error: Groovyc: The variable [result] is declared final but is reassigned.*
> Since we use final in our codebase a lot (although it seems to be ignored by groovy 2.4), 
> we will have to adjust a lot of places to make our code groovy 3.0 compatible.



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