]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: Accept comma-separated list in case-statements of switchs
authorJukka-Pekka Iivonen <jp0409@jippii.fi>
Fri, 26 Mar 2010 14:12:00 +0000 (15:12 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 13 Dec 2017 21:12:54 +0000 (22:12 +0100)
  switch (i) {
  case 0, 1, 2:
    break;
  }

https://bugzilla.gnome.org/show_bug.cgi?id=614015

tests/Makefile.am
tests/parser/switch-statement.vala [new file with mode: 0644]
vala/valaparser.vala

index efc54d317c8b356d43a2475aec1f1d9729730264..eb009127e82613309323798a4a6bfc211eed157e 100644 (file)
@@ -315,6 +315,7 @@ TESTS = \
        annotations/deprecated.vala \
        annotations/description.vala \
        annotations/noaccessormethod.test \
+       parser/switch-statement.vala \
        $(NULL)
 
 NON_NULL_TESTS = \
diff --git a/tests/parser/switch-statement.vala b/tests/parser/switch-statement.vala
new file mode 100644 (file)
index 0000000..28f37f3
--- /dev/null
@@ -0,0 +1,13 @@
+void case_with_list () {
+       int i = 1;
+       switch (i) {
+       case 0, 1, 2:
+               break;
+       default:
+               assert_not_reached ();
+       }
+}
+
+void main () {
+       case_with_list ();
+}
index 59b4d5f299f896da8a0a25c91db329369b493d55..ec5e34e82034460d67ff1265ec014f534d2bec9c 100644 (file)
@@ -1907,6 +1907,10 @@ public class Vala.Parser : CodeVisitor {
                        do {
                                if (accept (TokenType.CASE)) {
                                        section.add_label (new SwitchLabel (parse_expression (), get_src (begin)));
+                                       while (current () == TokenType.COMMA) {
+                                               expect (TokenType.COMMA);
+                                               section.add_label (new SwitchLabel (parse_expression (), get_src (begin)));
+                                       }
                                } else {
                                        expect (TokenType.DEFAULT);
                                        section.add_label (new SwitchLabel.with_default (get_src (begin)));