groovy
  1. groovy
  2. GROOVY-3927

Switch's default case doesn't return the value as the non-default cases do

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7-rc-1
    • Fix Version/s: 1.6.8, 1.7-rc-2
    • Component/s: Compiler
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      Reported by Guillaume on the groovy-dev mailing-list:

      def m3(s) {
         switch(s) {
             case 'a': 'letter A'; break
             case 'b': 'letter B'; break
             default: 'Unknown letter'
         }
      }
      assert m3('a') == 'letter A' &&
         m3('b') == 'letter B' &&
         m3('z') == 'Unknown letter'
      

      I was expecting that m3('z') would return 'Unknown letter', as
      switch/case is the last statement in the method, and that the value
      returned by that switch would go through the default case.

        Activity

        Hide
        Roshan Dawrani added a comment -

        Fixed

        Show
        Roshan Dawrani added a comment - Fixed

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Roshan Dawrani
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: