diff --git a/uiop/stream.lisp b/uiop/stream.lisp
index bd0f8c318ca98b0f17394caf89d1d35880b95100..7103dbdf800c33e88ad65c26939363ca80748db7 100644
--- a/uiop/stream.lisp
+++ b/uiop/stream.lisp
@@ -632,7 +632,9 @@ Upon success, the KEEP form is evaluated and the file is is deleted unless it ev
            (beforef (gensym "BEFORE"))
            (afterf (gensym "AFTER")))
       `(flet (,@(when before
-                  `((,beforef (,@(when streamp `(,stream)) ,@(when pathnamep `(,pathname))) ,@before)))
+                  `((,beforef (,@(when streamp `(,stream)) ,@(when pathnamep `(,pathname)))
+                       ,@(when after `((declare (ignorable ,pathname))))
+                       ,@before)))
               ,@(when after
                   (assert pathnamep)
                   `((,afterf (,pathname) ,@after))))