GNU bug report logs - #9035
24.0.50; byte-compiler warnings with defstruct and lexical-binding

Previous Next

Package: emacs;

Reported by: Lawrence Mitchell <wence <at> gmx.li>

Date: Sat, 9 Jul 2011 14:35:01 UTC

Severity: minor

Tags: fixed, patch

Found in version 24.0.50

Fixed in version 24.1

Done: Lars Magne Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Lawrence Mitchell <wence <at> gmx.li>
To: 9035 <at> debbugs.gnu.org
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




This bug report was last modified 13 years and 308 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.