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

switch case misbehave with @Typechecked

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0.7, 2.1.1
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      you can try this in groovyconsole

      import groovy.transform.TypeChecked
      
      @TypeChecked
      def test(Map<String, String> token) {
        switch(token.type) {
          case 'case one':
            println '1'
            '1'
            break
          case 'case two':
            println '2'
            '2'
            break
          default:
            println '3'
            '3'
            break
        }
        //uncomment line below to get it right
        //'ok'
      }
      

      given

      test([type:'case one'])

      the result is

      1
      2
      3
      Result: 3
      

      After uncomment the 'ok' line, the result is

      1
      Result: ok
      

        Attachments

          Activity

            People

            • Assignee:
              melix Cédric Champeau
              Reporter:
              pootow Richard Zhang
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: