diff options
Diffstat (limited to 'tests/conformance/4-statements')
4 files changed, 13 insertions, 13 deletions
diff --git a/tests/conformance/4-statements/switch_duplicate_label_rejected.zc b/tests/conformance/4-statements/switch_duplicate_label_rejected.zc new file mode 100644 index 0000000..54f3b56 --- /dev/null +++ b/tests/conformance/4-statements/switch_duplicate_label_rejected.zc @@ -0,0 +1,6 @@ +// expect error: duplicate case label +// spec 4.7.2: a label seen twice in one switch is an error +include rt; +enum color { RED, GREEN }; +fn main() { int k = 1; switch (k) { case RED, GREEN: k = 2; case 2 - 1: k = 3; } return 0; } +// zc0: skip diff --git a/tests/conformance/4-statements/switch_duplicate_labels_first_wins.zc b/tests/conformance/4-statements/switch_duplicate_labels_first_wins.zc deleted file mode 100644 index 67a0204..0000000 --- a/tests/conformance/4-statements/switch_duplicate_labels_first_wins.zc +++ /dev/null @@ -1,11 +0,0 @@ -// expect: first/ -// spec 4.7.2: duplicate labels are not an error, the first matching case in source order runs -include rt; -void pn(int x) { rt.put_n(x); rt.put_c(10); } -void ps(char* s) { rt.put_s(s); rt.put_c(10); } -fn main() { - int k = 4; - switch (k) { case 4: ps("first"); case 4: ps("second"); } - return 0; -} -// zc0: skip diff --git a/tests/conformance/4-statements/switch_label_forms.zc b/tests/conformance/4-statements/switch_label_forms.zc index cfe2712..ef5e33b 100644 --- a/tests/conformance/4-statements/switch_label_forms.zc +++ b/tests/conformance/4-statements/switch_label_forms.zc @@ -1,5 +1,5 @@ // expect: neg/chr/sum/enum/ -// spec 4.7.1 and 3.14: labels are constant expressions (no precedence: 1 + 1 * 3 is 6) +// spec 4.7.1 and 3.14: labels are constant expressions (c precedence: 1 + 1 * 3 is 4) include rt; void pn(int x) { rt.put_n(x); rt.put_c(10); } enum color { RED, GREEN }; @@ -12,5 +12,5 @@ void t(int k) { } rt.put_c(10); } -fn main() { t(-1); t('a'); t(6); t(1); return 0; } +fn main() { t(-1); t('a'); t(4); t(1); return 0; } // zc0: skip diff --git a/tests/conformance/4-statements/switch_same_label_other_switch.zc b/tests/conformance/4-statements/switch_same_label_other_switch.zc new file mode 100644 index 0000000..bb52a94 --- /dev/null +++ b/tests/conformance/4-statements/switch_same_label_other_switch.zc @@ -0,0 +1,5 @@ +// expect: 2/ +// spec 4.7.2: equal labels in two different switches are fine +include rt; +fn main() { int k = 1; switch (k) { case 1: k = 2; } switch (k) { case 1: k = 9; case 2: rt.put_n(k); } rt.put_c(10); return 0; } +// zc0: skip |
