tell a grouped for header by its shape, not by a var in it
(for ((= s 0) (< s n) (++ s)) ...) passed the check and reached cc as a call of (= s 0).
This commit is contained in:
@@ -95,10 +95,10 @@ forms, and what remains."
|
||||
`(%begin ,@(map walk-expr comments) ,form)))
|
||||
|
||||
;;; (for init test step body ...). C's parens around the header, carried
|
||||
;;; over, leave a call of a `var' in init's slot and the body in test's
|
||||
;;; over, leave all three parts in init's slot and the body in test's
|
||||
(define (check-for-header form slots)
|
||||
(cond ((and (pair? slots) (pair? (car slots)) (pair? (caar slots))
|
||||
(eq? 'var (car (caar slots))))
|
||||
(cond ((and (pair? slots) (list? (car slots)) (= 3 (length (car slots)))
|
||||
(every pair? (car slots)))
|
||||
(sex-error form "a for header is not grouped: write (for init test step body ...)"))
|
||||
((< (length slots) 3)
|
||||
(sex-error form "malformed for: write (for init test step body ...)"))))
|
||||
|
||||
@@ -338,6 +338,9 @@ whitespace aside, THEN?"
|
||||
(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 "whatever its init is"
|
||||
(reports? (in-fn "(for ((= a 0) (< a 4) (++ a)) (g a))")
|
||||
"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"))
|
||||
|
||||
Reference in New Issue
Block a user