From: Maxime Devos <maximedevos@telenet.be>
To: 56751@debbugs.gnu.org
Subject: bug#56751: Protocol of parent record type is ignored
Date: Sun, 24 Jul 2022 22:56:58 +0200 [thread overview]
Message-ID: <08146bc1-f365-b224-05fe-119693065402@telenet.be> (raw)
[-- Attachment #1.1.1: Type: text/plain, Size: 2028 bytes --]
(import (rnrs records syntactic)
(rnrs base))
(define-record-type
(#{I have one field, but no need to set it, I'll do it myself}#
make-1 type-1?)
(fields (immutable #{field with a fixed value}# #{get first field
value}#))
(protocol
(lambda (%make)
(lambda ()
(#;(%make) ;; XXX unlike what is documented, this needs to be:
%make
;; instead. Bug in inmplementation or documentation? Not the issue
;; I wanted to note though.
"some value")))))
(assert (string=? (#{get first field value}# (make-1)) "some value")) ; ok
(define-record-type (#{the subtype}# make-2 type-2?)
(parent #{I have one field, but no need to set it, I'll do it myself}#))
;; The problem:
;;
;; Guile seems to have forgotten that the protocol of the supertype,
;; and hence asks for a value for the argument even though the protocol
;; of the original record type normally would give it a value.
;; (Ok, this is interpretation for the symptoms, I haven't yet tested
this against
;; the source code).
;;
;; This manifests as make-2 havng arity 1 though it should have arity 1:
#;
(assert (equal? (#{get first field value}# (make-2) "some value"))) ;;
--> wrong number of arguments to #<procedure ...>
;; We can due to the bug also break the abstraction: (see assert failure)
(assert (equal? (#{get first field value}# (make-2
'break-the-abstraction)) "some value")) ;; --> wrong number of arguments
to #<procedure ...>
;; Note: if I explicitly write the protocol for the subtype, then all
the problems disappear
;; (work-around). For an example in the wild, see the supertype
<lost-and-found> at
;;
<https://git.gnunet.org/gnunet-scheme.git/tree/gnu/gnunet/concurrency/lost-and-found.scm>
;; and the subtype at
<https://git.gnunet.org/gnunet-scheme.git/tree/gnu/gnunet/dht/client.scm#n583>
;; (Not the best example, as I give the new fields default values as
well, but you get the idea.)
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
reply other threads:[~2022-07-24 20:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=08146bc1-f365-b224-05fe-119693065402@telenet.be \
--to=maximedevos@telenet.be \
--cc=56751@debbugs.gnu.org \
/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.
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).