From 5943ca417c5930b082f31ec647975ce314c47a5c Mon Sep 17 00:00:00 2001 From: "Paul M. Rodriguez" Date: Wed, 13 Mar 2024 16:19:16 -0500 Subject: [PATCH] Preserve unused variable warnings in and-let* --- binding.lisp | 18 ++++++++++++------ tests/binding.lisp | 7 +++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/binding.lisp b/binding.lisp index 3aa0f93a..3c9815d6 100644 --- a/binding.lisp +++ b/binding.lisp @@ -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))))) diff --git a/tests/binding.lisp b/tests/binding.lisp index f321a74b..2695f1e0 100644 --- a/tests/binding.lisp +++ b/tests/binding.lisp @@ -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))))