reject a for whose header is grouped

C's parens carried over, ((var i int 0) (< i 4) (++ i)), left the
writer short of slots, and it died in caddr with no location; with a
long enough body it would have compiled the body into the header.

Fixes #42.
This commit is contained in:
2026-10-09 17:26:03 +03:00
parent ea0bed6deb
commit baf2f92fce
2 changed files with 26 additions and 0 deletions

View File

@@ -309,6 +309,22 @@ whitespace aside, THEN?"
;; A nested pointer chain used to silently lose a level:
;; (var p (* (* char))) emitted `char *p'
;; A grouped header, C's parens carried over, died in the writer with
;; `(caddr) bad argument type' and no location
(test-group "malformed for"
(test-assert "a grouped header is named"
(reports? (in-fn "(for ((var i int 0) (< i 4) (++ i)) (g i))")
"header is not grouped"))
(test-assert "even when the body fills the slots it left"
(reports? (in-fn "(for ((var i int 0) (< i 4) (++ i)) (g i) (g i) (g i))")
"header is not grouped"))
(test-assert "a short one gets the shape"
(reports? (in-fn "(for (var i int 0) (< i 4))")
"(for init test step body ...)"))
(test-assert "and both name the line"
(reports? "(fn f () void\n (for ((var i int 0) (< i 4) (++ i)) (g i)))"
"codegen.sex:2:")))
(test-group "malformed types are rejected"
(test-assert "nested pointer chain"
(reports? (in-fn "(var p (* (* char)))") "pointer chains are written flat"))