[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#9035: 24.0.50; byte-compiler warnings with defstruct and lexical-bin
From: |
Lawrence Mitchell |
Subject: |
bug#9035: 24.0.50; byte-compiler warnings with defstruct and lexical-binding |
Date: |
Sat, 09 Jul 2011 14:10:08 +0100 |
In files with lexical-binding set to t, structure definitions
with :read-only slots lead to a byte-compiler warning about
the unused variable cl-x.
To reproduce, byte-compile a file consisting of:
;; -*- lexical-binding: t -*-
(eval-when-compile (require 'cl))
(defstruct foo (name nil :read-only t))
This is due to the setf-method that is produced when expanding
the defstruct form:
(define-setf-method ... (cl-x)
(error (format "%s is a read-only slot" ...)))
The following patch fixes the problem by changing the setf-method
to:
(define-setf-method ... (cl-x)
(progn (ignore cl-x)
(error (format "%s is a read-only slot" ...))))
Commit message/changelog entry
Silence byte-compiler warning with :read-only defstruct slots
* emacs-lisp/cl-macs.el (defstruct): Ignore argument to setf method if
slot is read-only.
Patch:
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 2813cc4..6181c6b 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2389,8 +2389,10 @@ value, that slot cannot be set via `setf'.
(push (cons accessor t) side-eff)
(push (list 'define-setf-method accessor '(cl-x)
(if (cadr (memq :read-only (cddr desc)))
- (list 'error (format "%s is a read-only slot"
- accessor))
+ (list 'progn '(ignore cl-x)
+ (list 'error
+ (format "%s is a read-only slot"
+ 'accessor)))
;; If cl is loaded only for compilation,
;; the call to cl-struct-setf-expander would
;; cause a warning because it may not be
- bug#9035: 24.0.50; byte-compiler warnings with defstruct and lexical-binding,
Lawrence Mitchell <=