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
    • 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

      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

        Roshan Dawrani created issue -
        Roshan Dawrani made changes -
        Field Original Value New Value
        Fix Version/s 1.6.8 [ 16019 ]
        Fix Version/s 1.7.1 [ 16014 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.8-beta-1 [ 16013 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Fix Version/s 1.7-rc-2 [ 16011 ]
        Fix Version/s 1.8-beta-1 [ 16013 ]
        Fix Version/s 1.7.1 [ 16014 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12732889 ] Default workflow, editable Closed status [ 12744704 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12970595 ] Default workflow, editable Closed status [ 12978327 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development