refuse a statement of the wrong shape

(goto), (var q), (cast i), (while) and the like died in the writer, in
CHICKEN's words about a procedure of its own and with no location;
(return 1 2), (break 1) and (sizeof a b) dropped what was extra.
This commit is contained in:
2026-10-19 10:23:59 +03:00
parent 6ecaa110f6
commit 21554013c9
2 changed files with 56 additions and 0 deletions

View File

@@ -424,6 +424,36 @@ whitespace aside, THEN?"
(reports? "(fn f () void\n (for ((var i int 0) (< i 4) (++ i)) (g i)))"
"codegen.sex:2:")))
;; each of these died in the writer, in CHICKEN's words about a
;; procedure of the writer's, and with no location
(test-group "malformed forms"
(test-assert "a goto names one label"
(reports? (in-fn "(goto)") "malformed goto: write (goto label)"))
(test-assert "and only one"
(reports? (in-fn "(goto a b)") "malformed goto"))
(test-assert "so does a label"
(reports? (in-fn "(: a b)") "malformed :: write (: label)"))
(test-assert "a var has a name and a type"
(reports? (in-fn "(var q)") "malformed var"))
(test-assert "and a value at most"
(reports? (in-fn "(var q int 1 2)") "malformed var"))
(test-assert "a cast a value and a type"
(reports? (in-fn "(var n int (cast a))") "malformed cast: write (cast value type)"))
(test-assert "a while its test"
(reports? (in-fn "(while)") "malformed while"))
(test-assert "an if its test and what it does"
(reports? (in-fn "(if a)") "malformed if"))
(test-assert "a return one value at most"
(reports? (in-fn "(return 1 2)") "malformed return"))
(test-assert "a break none"
(reports? (in-fn "(while a (break 1))") "malformed break"))
(test-assert "a sizeof one operand"
(reports? (in-fn "(var n size-t (sizeof a b))") "malformed sizeof"))
(test-assert "a global var is held to the same"
(reports? "(var q)" "malformed var"))
(test-assert "each naming its line"
(reports? "(fn f () void\n (goto))" "codegen.sex:2: malformed goto")))
;; a block of nothing had nothing for c-begin to begin with, and the
;; writer died on its arity
(test-group "empty bodies"