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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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

      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.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: