unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#67788] [PATCH] records: Check for missing mandatory innate fields when inheriting.
@ 2023-12-11 22:09 Skyler Ferris via Guix-patches via
  2023-12-28  0:30 ` [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
  0 siblings, 2 replies; 5+ messages in thread
From: Skyler Ferris via Guix-patches via @ 2023-12-11 22:09 UTC (permalink / raw)
  To: 67788
  Cc: Skyler Ferris, Christopher Baines, Josselin Poiret,
	Ludovic Courtès, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

This 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 fixes issue #67785 by providing the same error message that is
provided when the value is not inherited.

After applying this patch `make check` had one failure, which seems to
be unrelated. It was the test "pypi->guix-package, no wheel"; for some
reason, the download of the wheel file failed. All other tests, in
particular the tests in `tests/records.scm`, passed.

I additionally manually inspected the values computed in the `let*`
against a type that contained 4 fields, for each combination of
mandatory/non-mandatory and optional/non-optional, and they contained
the expected values.

 guix/records.scm | 9 +++++++++
 1 file changed, 9 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)

base-commit: 2b782f67266b42bb40015bd23ce2443be2f9b01f
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-13 19:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [bug#67788] records: Check for missing mandatory innate fields when, inheriting Skyler Ferris via Guix-patches via
2023-12-28  2:05   ` 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

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