refuse a malformed closure capture
((+ a 1)) was a capture named `+' holding a.
This commit is contained in:
@@ -1863,8 +1863,9 @@
|
|||||||
;;; `(* int)' inside the body and `a' is never mentioned there.
|
;;; `(* int)' inside the body and `a' is never mentioned there.
|
||||||
(define (capture-binding capture form env)
|
(define (capture-binding capture form env)
|
||||||
(let ((name (capture-name capture)))
|
(let ((name (capture-name capture)))
|
||||||
(unless (symbol? name)
|
;; ((+ a 1)) was a capture named `+' holding a
|
||||||
(sex-error form "a closure capture needs a name" capture))
|
(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)
|
;; the same lookup either way, so `(closure ((x int)) int (scale)
|
||||||
;; ...)' borrows a global's `scale' as readily as a local's
|
;; ...)' borrows a global's `scale' as readily as a local's
|
||||||
(let ((type (expression-type (capture-argument capture) env)))
|
(let ((type (expression-type (capture-argument capture) env)))
|
||||||
|
|||||||
@@ -469,6 +469,10 @@
|
|||||||
;; captures are a closure's other parameters, under C's rule for
|
;; captures are a closure's other parameters, under C's rule for
|
||||||
;; those: no two alike, and none redeclared at the body's top level.
|
;; those: no two alike, and none redeclared at the body's top level.
|
||||||
;; Both were C's redefinition errors
|
;; Both were C's redefinition errors
|
||||||
|
;; ((+ a 1)) was a capture named `+', holding a
|
||||||
|
(test-assert "a capture is a name, or a name and a value"
|
||||||
|
(reports? (in-fn "(var c (closure () int) (closure () int ((+ a 1)) (return 1)))")
|
||||||
|
"a capture is a name, or (name value)"))
|
||||||
(test-assert "a capture named like a parameter is refused"
|
(test-assert "a capture named like a parameter is refused"
|
||||||
(reports? (in-fn "(var c (closure ((int)) int) (closure ((a int)) int (a) (return a)))")
|
(reports? (in-fn "(var c (closure ((int)) int) (closure ((a int)) int (a) (return a)))")
|
||||||
"a capture and a parameter share a name"))
|
"a capture and a parameter share a name"))
|
||||||
|
|||||||
Reference in New Issue
Block a user