unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Ivan Andrus <darthandrus@gmail.com>
Cc: 12604-done@debbugs.gnu.org
Subject: bug#12604: 24.2.50; No error when setting read-only defstruct slot
Date: Mon, 08 Oct 2012 23:15:30 -0400	[thread overview]
Message-ID: <jwv4nm4snfb.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <39C98324-A281-4DA9-96CD-878280F88DF1@gmail.com> (Ivan Andrus's message of "Mon, 8 Oct 2012 18:54:05 +0200")

> The following Elisp does not raise an error, but it should (and did
> e.g. in 24.1).
[...]
>   (predicate nil :read-only t)
[...]
> (setf (emacs-achievement-predicate bob) t)

Very good point, indeed.
I installed the patch below which should fix this,


        Stefan


=== modified file 'lisp/emacs-lisp/cl-macs.el'
--- lisp/emacs-lisp/cl-macs.el	2012-10-06 17:34:57 +0000
+++ lisp/emacs-lisp/cl-macs.el	2012-10-08 20:44:22 +0000
@@ -2324,26 +2324,29 @@
                           (if (= pos 0) '(car cl-x)
                             `(nth ,pos cl-x)))) forms)
 	      (push (cons accessor t) side-eff)
-              ;; Don't bother defining a setf-expander, since gv-get can use
-              ;; the compiler macro to get the same result.
-              ;;(push `(gv-define-setter ,accessor (cl-val cl-x)
-              ;;         ,(if (cadr (memq :read-only (cddr desc)))
-              ;;              `(progn (ignore cl-x cl-val)
-              ;;                      (error "%s is a read-only slot"
-              ;;                             ',accessor))
+              (if (cadr (memq :read-only (cddr desc)))
+                  (push `(gv-define-expander ,accessor
+                           (lambda (_cl-do _cl-x)
+                             (error "%s is a read-only slot" ',accessor)))
+                        forms)
+                ;; For normal slots, we don't need to define a setf-expander,
+                ;; since gv-get can use the compiler macro to get the
+                ;; same result.
+                ;; (push `(gv-define-setter ,accessor (cl-val cl-x)
               ;;            ;; If cl is loaded only for compilation,
               ;;            ;; the call to cl--struct-setf-expander would
               ;;            ;; cause a warning because it may not be
               ;;            ;; defined at run time.  Suppress that warning.
-              ;;            `(progn
+                ;;          (progn
               ;;               (declare-function
               ;;                cl--struct-setf-expander "cl-macs"
               ;;                (x name accessor pred-form pos))
               ;;               (cl--struct-setf-expander
               ;;                cl-val cl-x ',name ',accessor
               ;;                ,(and pred-check `',pred-check)
-              ;;                ,pos))))
+                ;;             ,pos)))
               ;;      forms)
+                )
 	      (if print-auto
 		  (nconc print-func
 			 (list `(princ ,(format " %s" slot) cl-s)






      reply	other threads:[~2012-10-09  3:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-08 16:54 bug#12604: 24.2.50; No error when setting read-only defstruct slot Ivan Andrus
2012-10-09  3:15 ` Stefan Monnier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv4nm4snfb.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=12604-done@debbugs.gnu.org \
    --cc=darthandrus@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).