guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#67788] [PATCH] records: Check for missing mandatory innate fields w


From: Skyler Ferris
Subject: [bug#67788] [PATCH] records: Check for missing mandatory innate fields when inheriting.
Date: Mon, 11 Dec 2023 14:09:19 -0800

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]