unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Skyler Ferris via Guix-patches via <guix-patches@gnu.org>
To: 67788@debbugs.gnu.org
Subject: [bug#67788] records: Check for missing mandatory innate fields when, inheriting.
Date: Thu, 28 Dec 2023 00:30:56 +0000	[thread overview]
Message-ID: <aabc0db6-418f-4d2f-8528-00c44ec5d234@protonmail.com> (raw)
In-Reply-To: <5a0f596c5bbcc75e3ca50d37066f42baca354236.1702330063.git.skyvine@protonmail.com>

his gives the user a more helpful error message if they inherit from
another instance but forget to supply a value for a field which is
innate and has no default.

* guix/records.scm (record-inheritance): Check for missing innate fields

Change-Id: I08b898d8da551af50aa5b0b60187dcad8d259bc1
---
# This version of the commit addse a test case which confirms that
# theuseful commit message is given. It is based on the test immediately
# above it, which checks for the error message in the non-innate case.
#
# Additionally, I can now confirm that all tests pass with this commit.
# The failures I noted previously were indeed environmental problems and
# have been resolved locally (and were unrelated to the commit).
  guix/records.scm  |  9 +++++++++
  tests/records.scm | 18 ++++++++++++++++++
  2 files changed, 27 insertions(+)

diff --git a/guix/records.scm b/guix/records.scm
index f4d12a861d..109c5cf4dc 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -161,6 +161,15 @@ (define-syntax make-syntactic-constructor
                 (record-error 'name s "extraneous field initializers ~a"
                               unexpected)))

+           ;; Make sure all mandatory and innate fields are included.
+           (let* ((fields           (map (compose car syntax->datum) 
field+value))
+                  (optional         (map (compose car syntax->datum) 
'defaults))
+                  (mandatory        (lset-difference eq? '(expected 
...) optional))
+                  (mandatory+innate (lset-intersection eq? mandatory 
'innate))
+                  (missing          (lset-difference eq? 
mandatory+innate fields)))
+             (when (pair? missing)
+               (record-error 'name s "missing field initializers ~a" 
missing)))
+
             #`(make-struct/no-tail type
                            #,@(map (lambda (field index)
                                      (or (field-inherited-value field)
diff --git a/tests/records.scm b/tests/records.scm
index 5464892d3b..39f4bfdf9c 100644
--- a/tests/records.scm
+++ b/tests/records.scm
@@ -402,6 +402,24 @@ (define (location-alist loc)
             (string-match "missing .*initialize.*baz" message)
             (equal? form '(foo))))))

+(test-assert "define-record-type* & innate & missing initializers"
+  (catch 'syntax-error
+    (lambda ()
+      (eval '(begin
+               (define-record-type* <foo> foo make-foo
+                 foo?
+                 (bar foo-bar (default 42))
+                 (baz foo-baz (innate)))
+
+               (let ((base (foo (bar #t) (baz #t))))
+                 (foo (inherit base))))
+            (test-module))
+      #f)
+    (lambda (key proc message location form . args)
+      (and (eq? proc 'foo)
+           (string-match "missing .*initialize.*baz" message)
+           (equal? form '(foo (inherit base)))))))
+
  (test-assert "define-record-type* & extra initializers"
    (catch 'syntax-error
      (lambda ()

base-commit: fe86819d8bde674766659c22b215d3a689a8026e
-- 
2.41.0







  reply	other threads:[~2023-12-28  0:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-11 22:09 [bug#67788] [PATCH] records: Check for missing mandatory innate fields when inheriting Skyler Ferris via Guix-patches via
2023-12-28  0:30 ` Skyler Ferris via Guix-patches via [this message]
2023-12-28  2:05   ` [bug#67788] records: Check for missing mandatory innate fields when, inheriting Skyler Ferris via Guix-patches via
2024-01-13 19:00 ` [bug#67788] doc: Add documentation for define-record-type* skyvine--- via Guix-patches via
2024-01-13 18:57   ` [bug#67786] " Skyler Ferris via Guix-patches via

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://guix.gnu.org/

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

  git send-email \
    --in-reply-to=aabc0db6-418f-4d2f-8528-00c44ec5d234@protonmail.com \
    --to=guix-patches@gnu.org \
    --cc=67788@debbugs.gnu.org \
    --cc=skyvine@protonmail.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/guix.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).