aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2024-03-24 18:18:41 +0100
committerMattias EngdegÄrd2024-03-29 11:39:38 +0100
commitb20866c4b3aa1446efda252bd5c3fa54f68c5d7f (patch)
treea04cac9fba44f1eb241c39075c99e32555c58987
parentcbd862865ff0a08d1214ac33590e7af80d10a0ac (diff)
downloademacs-b20866c4b3aa1446efda252bd5c3fa54f68c5d7f.tar.gz
emacs-b20866c4b3aa1446efda252bd5c3fa54f68c5d7f.zip
Better `sort` ignored-return-value warning
* lisp/emacs-lisp/bytecomp.el (byte-compile-form) (bytecomp--actually-important-return-value-p): Special handling of `sort` that takes into account that it may return an important value depending on the :in-place keyword argument.
-rw-r--r--lisp/emacs-lisp/bytecomp.el16
1 files changed, 14 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 7af568cfe34..2b5eb34e571 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3445,6 +3445,7 @@ lambda-expression."
3445 ((and (or sef (function-get (car form) 'important-return-value)) 3445 ((and (or sef (function-get (car form) 'important-return-value))
3446 ;; Don't warn for arguments to `ignore'. 3446 ;; Don't warn for arguments to `ignore'.
3447 (not (eq byte-compile--for-effect 'for-effect-no-warn)) 3447 (not (eq byte-compile--for-effect 'for-effect-no-warn))
3448 (bytecomp--actually-important-return-value-p form)
3448 (byte-compile-warning-enabled-p 3449 (byte-compile-warning-enabled-p
3449 'ignored-return-value (car form))) 3450 'ignored-return-value (car form)))
3450 (byte-compile-warn-x 3451 (byte-compile-warn-x
@@ -3471,6 +3472,15 @@ lambda-expression."
3471 (if byte-compile--for-effect 3472 (if byte-compile--for-effect
3472 (byte-compile-discard))))) 3473 (byte-compile-discard)))))
3473 3474
3475(defun bytecomp--actually-important-return-value-p (form)
3476 "Whether FORM is really a call with a return value that should not go unused.
3477This assumes the function has the `important-return-value' property."
3478 (cond ((eq (car form) 'sort)
3479 ;; For `sort', we only care about non-destructive uses.
3480 (and (zerop (% (length form) 2)) ; new-style call
3481 (not (plist-get (cddr form) :in-place))))
3482 (t t)))
3483
3474(let ((important-return-value-fns 3484(let ((important-return-value-fns
3475 '( 3485 '(
3476 ;; These functions are side-effect-free except for the 3486 ;; These functions are side-effect-free except for the
@@ -3478,9 +3488,11 @@ lambda-expression."
3478 mapcar mapcan mapconcat 3488 mapcar mapcan mapconcat
3479 assoc plist-get plist-member 3489 assoc plist-get plist-member
3480 3490
3481 ;; It's safe to ignore the value of `sort' and `nreverse' 3491 ;; It's safe to ignore the value of `nreverse'
3482 ;; when used on arrays, but most calls pass lists. 3492 ;; when used on arrays, but most calls pass lists.
3483 nreverse sort 3493 nreverse
3494
3495 sort ; special handling (non-destructive calls only)
3484 3496
3485 match-data 3497 match-data
3486 3498