diff mbox series

[bug#67788] records: Check for missing mandatory innate fields when inheriting.

Message ID 5a0f596c5bbcc75e3ca50d37066f42baca354236.1702330063.git.skyvine@protonmail.com
State New
Headers show
Series [bug#67788] records: Check for missing mandatory innate fields when inheriting. | expand

Commit Message

Skyler Ferris Dec. 11, 2023, 10:09 p.m. UTC
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(+)


base-commit: 2b782f67266b42bb40015bd23ce2443be2f9b01f
diff mbox series

Patch

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)