GNU bug report logs - #46175
Redefinable classes clobber custom slot options

Previous Next

Package: guile;

Reported by: "Thompson, David" <dthompson2 <at> worcester.edu>

Date: Fri, 29 Jan 2021 16:44:02 UTC

Severity: normal

Done: Andy Wingo <wingo <at> pobox.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 46175 in the body.
You can then email your comments to 46175 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#46175; Package guile. (Fri, 29 Jan 2021 16:44:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Thompson, David" <dthompson2 <at> worcester.edu>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Fri, 29 Jan 2021 16:44:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Thompson, David" <dthompson2 <at> worcester.edu>
To: bug-guile <at> gnu.org
Subject: Redefinable classes clobber custom slot options
Date: Fri, 29 Jan 2021 11:43:35 -0500
[Message part 1 (text/plain, inline)]
The compute-slots method for <redefinable-class> does a transformation
of #:allocation #:instance slots to #:allocation #:virtual slots, but
in doing so it discards all slot options besides the standard ones.
This means that a metaclass that inherits from <redefinable-class>
won't work as expected if it relies upon custom slot options.

Test case:

    (use-modules (oop goops)
                 (srfi srfi-111))

    (define-class <meta> (<class>))

    (define (boxed-slot? slot)
      (get-keyword #:box? (slot-definition-options slot)))

    (define-method (compute-getter-method (class <meta>) slot)
      (if (boxed-slot? slot)
          (make <method>
            #:specializers (list class)
            #:procedure (let ((slot-name (slot-definition-name slot)))
                          (lambda (obj)
                            (unbox (slot-ref obj slot-name)))))
          (next-method)))

    (define-method (compute-setter-method (class <meta>) slot)
      (if (boxed-slot? slot)
          (make <method>
            #:specializers (list class <top>)
            #:procedure (let ((slot-name (slot-definition-name slot)))
                          (lambda (obj value)
                            (set-box! (slot-ref obj slot-name) value))))
          (next-method)))

    (define-class <redefinable-meta> (<meta> <redefinable-class>))

    (define-class <foo> ()
      (bar #:accessor bar #:box? #t #:init-form (box 123))
      #:metaclass <meta>)

    (define-class <redefinable-foo> ()
      (bar #:accessor bar #:box? #t #:init-form (box 123))
      #:metaclass <redefinable-meta>)

    ;; This works:
    (pk (+ (bar (make <foo>)) 456))

    ;; This throws an error:
    (pk (+ (bar (make <redefinable-foo>)) 456))

Attached is a patch that preserves all slot options that redefinable
classes do not need to alter, including custom ones.  How does it
look?

- Dave
[0001-goops-Preserve-all-slot-options-in-redefinable-class.patch (text/x-patch, attachment)]

Reply sent to Andy Wingo <wingo <at> pobox.com>:
You have taken responsibility. (Sat, 20 Mar 2021 19:03:02 GMT) Full text and rfc822 format available.

Notification sent to "Thompson, David" <dthompson2 <at> worcester.edu>:
bug acknowledged by developer. (Sat, 20 Mar 2021 19:03:02 GMT) Full text and rfc822 format available.

Message #10 received at 46175-done <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: "Thompson, David" <dthompson2 <at> worcester.edu>
Cc: 46175-done <at> debbugs.gnu.org
Subject: Re: bug#46175: Redefinable classes clobber custom slot options
Date: Sat, 20 Mar 2021 20:02:29 +0100
On Fri 29 Jan 2021 17:43, "Thompson, David" <dthompson2 <at> worcester.edu> writes:

> The compute-slots method for <redefinable-class> does a transformation
> of #:allocation #:instance slots to #:allocation #:virtual slots, but
> in doing so it discards all slot options besides the standard ones.
> This means that a metaclass that inherits from <redefinable-class>
> won't work as expected if it relies upon custom slot options.

Thanks for the report; patch applied!

Andy




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 18 Apr 2021 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 345 days ago.

Previous Next


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