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:
@@ -486,9 +486,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))
|
||||
@@ -543,7 +542,7 @@
|
||||
(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)
|
||||
(with-scope env (lambda () (walk-parts form env))))
|
||||
|
||||
((lambda)
|
||||
|
||||
Reference in New Issue
Block a user