make a declaring case body a block

A case body shared the switch's scope, so two cases could not each
declare `bits', and a label could not be followed by a declaration
before C23; inference shared the scope too, and typed a later case's
read of an outer name as the earlier case's local.

Fixes #51.
This commit is contained in:
2026-10-09 17:23:42 +03:00
parent 52228e6fc6
commit 3e01fe41e8
4 changed files with 46 additions and 14 deletions

View File

@@ -501,9 +501,8 @@
;;; (while (< v 0) (var v char 1) ...)
;;; (var m _ (+ v 1)) ; double, not char
;;;
;;; One frame per form, not one per arm: a `case' label opens no scope
;;; in C, and an `if' arm can only declare inside a `do', which brings
;;; its own.
;;; A `case' body gets one too, being written as a block. An `if' arm
;;; gets none: it can only declare inside a `do', which brings its own.
(define (declare-name! env name type)
(hash-table-set! (car (hash-table-ref env :scopes)) name type))
@@ -583,14 +582,10 @@
(cons walk-embed-result (walk-body expansion env)))))
(else
(case (car form)
((do for while if switch)
((do for while if switch case case/fallthrough default)
(parameterize ((operand-position? #f))
(with-scope env (lambda () (walk-parts form env)))))
((case case/fallthrough default)
(parameterize ((operand-position? #f))
(walk-parts form env)))
((lambda)
(let ((name (aux-name! env make-lambda-name)))
(add-aux-code! env (lift-lambda name form))