refuse a malformed closure capture

((+ a 1)) was a capture named `+' holding a.
This commit is contained in:
2026-10-19 10:23:59 +03:00
parent 77a53da276
commit 893e9b2848
2 changed files with 7 additions and 2 deletions

View File

@@ -1863,8 +1863,9 @@
;;; `(* int)' inside the body and `a' is never mentioned there.
(define (capture-binding capture form env)
(let ((name (capture-name capture)))
(unless (symbol? name)
(sex-error form "a closure capture needs a name" capture))
;; ((+ a 1)) was a capture named `+' holding a
(unless (and (symbol? name) (or (symbol? capture) (= 2 (length capture))))
(sex-error form "a capture is a name, or (name value)" capture))
;; the same lookup either way, so `(closure ((x int)) int (scale)
;; ...)' borrows a global's `scale' as readily as a local's
(let ((type (expression-type (capture-argument capture) env)))