special-form heads are not shadowable
Found in a read/eval review: a local named like a special form wrongly took over operator position. (let [if (fn ...)] (if true 1 2)) returned the fn, but per spec section 3 (and the reference) special-form heads are not shadowable; only macros are. Two fixes: drop the (not shadowed) guard on the special-form branch of analyze-list (so an (if ...) head is always the special), and prefix a local whose name is a Scheme keyword when emitting (so a value local legally named if does not shadow the (if ...) the back end emits). Value-position locals named if/or/case still work.
This commit is contained in:
parent
f18ae3bd46
commit
212cd0399a
5 changed files with 106 additions and 81 deletions
|
|
@ -465,7 +465,10 @@
|
|||
;; read -> macroexpand -> analyze. A local shadows both.
|
||||
(and (form-sym? head) (not shadowed) (form-macro? ctx head))
|
||||
(analyze ctx (form-expand-1 ctx form) env)
|
||||
(and hname (not shadowed) (contains? handled hname))
|
||||
;; special-form heads are NOT shadowable (unlike macros): a local named
|
||||
;; `if` does not change the meaning of (if …) in operator position, per
|
||||
;; spec §3 and the reference. No (not shadowed) guard here.
|
||||
(and hname (contains? handled hname))
|
||||
(analyze-special ctx hname items env)
|
||||
(and hname (not shadowed) (method-head? hname))
|
||||
(analyze-host-call ctx hname items env)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue