require case labels to be values written once
(case (1 2) ...) is a list of labels, so (case (+ 1 1) ...) came out case +: case 1: case 1:, and a value repeated in a switch was left to C to report, without saying where.
This commit is contained in:
@@ -35,6 +35,23 @@
|
||||
(not (followed-by? (in-fn "(switch a (case 1 (do (var x int 1) (g x))))")
|
||||
"{" "{"))))
|
||||
|
||||
;; (case (1 2) ...) is two labels, so (case (+ 1 1) ...) came out as
|
||||
;; three, the first of them `case +:'
|
||||
(test-group "case labels"
|
||||
(test-assert "a list of them is a case each"
|
||||
(followed-by? (in-fn "(switch a (case (1 B) (g a)))") "case 1:" "case B:"))
|
||||
(test-assert "an operator is not one"
|
||||
(reports? (in-fn "(switch a (case (+ 1 1) (g a)))") "a case label is a value"))
|
||||
(test-assert "nor is an expression in the list"
|
||||
(reports? (in-fn "(switch a (case (1 (- 2)) (g a)))") "a case label is a value"))
|
||||
(test-assert "a value is written once"
|
||||
(reports? (in-fn "(switch a (case (1 2 1) (g a)))") "case label written twice"))
|
||||
(test-assert "in the whole switch"
|
||||
(reports? (in-fn "(switch a (case 1 (g a)) (case/fallthrough (2 1)) (default (g b)))")
|
||||
"case label written twice"))
|
||||
(test-assert "each switch apart"
|
||||
(emits? (in-fn "(switch a (case 1 (g a))) (switch b (case 1 (g b)))") "case 1:")))
|
||||
|
||||
;; c-switch handed its scrutinee straight to `cat', which only works
|
||||
;; when it is an atom. Anything else was displayed as a raw
|
||||
;; s-expression: `switch ((%. e type))'.
|
||||
|
||||
Reference in New Issue
Block a user