unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#56751: Protocol of parent record type is ignored
@ 2022-07-24 20:56 Maxime Devos
  0 siblings, 0 replies; only message in thread
From: Maxime Devos @ 2022-07-24 20:56 UTC (permalink / raw)
  To: 56751


[-- 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 --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-24 20:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-24 20:56 bug#56751: Protocol of parent record type is ignored Maxime Devos

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).