Skip to content

Commit

Permalink
Preserve unused variable warnings in and-let*
Browse files Browse the repository at this point in the history
  • Loading branch information
ruricolist committed Mar 13, 2024
1 parent da8ee8a commit 5943ca4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 12 additions & 6 deletions binding.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,18 @@ Also, this version makes the bindings immutable."
((list* (and var (type symbol)) clauses)
`(and ,var ,@(expand clauses body)))
((list* (list var expr) clauses)
(multiple-value-bind (local other)
(partition-declarations (list var) decls env)
`(let1 ,var ,expr
,@local
(and ,var ,@(expand clauses
(append other body))))))
(let ((temp (gensym (string var))))
(multiple-value-bind (local-decls other-decls)
(partition-declarations (list var) decls env)
;; The use of the temporary here is so we still
;; get style warnings if the variable is
;; unused.
`(let* ((,temp ,expr)
(,var ,temp))
,@local-decls
(and ,temp
,@(expand clauses
(append other-decls body)))))))
((list* (list expr) clauses)
`(and ,expr ,@(expand clauses body)))))))
(car (expand clauses body)))))
Expand Down
7 changes: 7 additions & 0 deletions tests/binding.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,10 @@
(expect '(let ((x 0)) (and-let* (x (y (- x 1)) ((plusp y))) (/ x y))) nil)
(expect '(let ((x nil)) (and-let* (x (y (- x 1)) ((plusp y))) (/ x y))) nil)
(expect '(let ((x 3)) (and-let* (x (y (- x 1)) ((plusp y))) (/ x y))) (/ 3 2))))

#+(or sbcl ccl)
(test and-let-unused ()
(signals style-warning
(eval `(and-let* ((x 1)
(y 2))
x))))

0 comments on commit 5943ca4

Please sign in to comment.