branch: elpa/loopy
commit fff3936e6156a88b9b4f2e113fb0eaff5062952b
Author: okamsn <[email protected]>
Commit: GitHub <[email protected]>
Fix warning by avoiding `pcase` patterns for symbols in `loopy-let*`. (#257)
The warning was triggered by the pattern `(loopy SYMBOL)`, which resolves
to the pattern `SYMBOL`, shadowing the pattern `fail`. Since the error message
cannot be reached anyway when destructuring is not used, we use `let` to bind
the variable to the matched, non-destructured value instead.
---
lisp/loopy.el | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/lisp/loopy.el b/lisp/loopy.el
index b0f0017cc7c..4d1172a990d 100644
--- a/lisp/loopy.el
+++ b/lisp/loopy.el
@@ -1052,10 +1052,17 @@ instead of this macro."
;; NOTE: We don't use `pcase-let*' here because we want to keep
;; the signal of `loopy-bad-run-time-destructuring'.
(cl-flet ((pcase-maker ((var val) body)
- `(pcase ,val
- ((loopy ,var) ,body)
- (fail (signal 'loopy-bad-run-time-destructuring
- (list (quote (loopy ,var)) fail))))))
+ ;; Using `(loopy SYMBOL)' as a pattern still triggers
+ ;; the warning for shadowing the all-matching pattern `fail',
+ ;; so instead we use a `let' binding when VAR is a symbol
+ ;; to avoid `pcase'.
+ (if (symbolp var)
+ `(let ((,var ,val))
+ ,body)
+ `(pcase ,val
+ ((loopy ,var) ,body)
+ (fail (signal 'loopy-bad-run-time-destructuring
+ (list (quote (loopy ,var)) fail)))))))
(cl-loop with rev = (reverse bindings)
with result = (pcase-maker (car rev) (macroexp-progn body))
for bind in (cdr rev)