Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5984

Weird behaviour of switch-case-break statement with @CompileStatic

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.1.1
    • Component/s: Static compilation
    • Environment:
      groovy sdk 2.1.0
      Oracle JDK build 1.7.0_13-b20 on Mac OS X Lion 10.7.5

      Description

      It seems that break s are ignored in switch-case statements when @CompileStatic is used.

      • Test case 1:
        Test.groovy
        import groovy.transform.CompileStatic
        @CompileStatic
        class Test {
            def test() {
                ['A', 'B', 'C'].each { String val ->
                    switch (val) {
                        case 'A' :
                            println("${val} caseA")
                            break
                        case 'B' :
                            println("${val} caseB")
                            break
                        default : 
                            println("${val} default")
                    }
                }
            }
        }
        (new Test()).test()
        

      Output:

      A caseA
      A caseB
      A default
      B caseB
      B default
      C default
      
      • Test case 2:
        just comment @CompileStatic

      And everithing works fine:

      A caseA
      B caseB
      C default
      

        Attachments

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              telecommit Igor Kovalchuk
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: