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/03/02 20:14:00 UTC

[jira] [Updated] (GROOVY-9880) Switch incorrectly falls through default case

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

Eric Milles updated GROOVY-9880:
--------------------------------
    Fix Version/s: 3.0.8

> Switch incorrectly falls through default case
> ---------------------------------------------
>
>                 Key: GROOVY-9880
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9880
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.7
>         Environment: Using Groovy-Eclipse 4.0.0 under Ubuntu 18.04
>            Reporter: Javier MV
>            Assignee: Eric Milles
>            Priority: Minor
>             Fix For: 3.0.8, 4.0.0-alpha-3
>
>
> When 'switch' is inside a Closure a weird condition causes 'default' case to be invoked, after another 'case' condition was met (even if 'break' was present).
> Minimal example:
> { it ->
>      {{switch('a') {}}
>      case 'a':
>          print 'hi!'
>          if (false)
>              print 'x'
>          break
>      {{default: println 'bye'}}
>     }
> {{}.call()}}
> Prints "hi!bye" as it is, but only "hi!" if outside the Closure. Adding an empty 'else \{ }' to the 'if' works as a poor man's fix.
>  



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