forked from alex-eg/sex
refuse a closure capturing one name twice
check-capture-names held captures against the parameters and the body, not against each other: (n n) gave C two members and two parameters n.
This commit is contained in:
@@ -2031,6 +2031,11 @@
|
||||
(when (memq name parameters)
|
||||
(sex-error form "a capture and a parameter share a name" name)))
|
||||
names)
|
||||
(let twice ((names names))
|
||||
(when (pair? names)
|
||||
(when (memq (car names) (cdr names))
|
||||
(sex-error form "two captures share a name" (car names)))
|
||||
(twice (cdr names))))
|
||||
(for-each (lambda (statement)
|
||||
(match statement
|
||||
(('var (? symbol? name) . _)
|
||||
|
||||
@@ -498,6 +498,9 @@
|
||||
(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)))")
|
||||
"a capture and a parameter share a name"))
|
||||
(test-assert "so is one captured twice"
|
||||
(reports? (in-fn "(var c (closure () int) (closure () int (a a) (return a)))")
|
||||
"two captures share a name"))
|
||||
(test-assert "so is one redeclared at the top of the body"
|
||||
(reports? (in-fn "(var c (closure () int) (closure () int (a) (var a int 5) (return a)))")
|
||||
"the body redeclares a capture"))
|
||||
|
||||
Reference in New Issue
Block a user