From a1906758c31036c30f8c11703daa4202adde8dac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Thu, 17 Jul 2014 16:45:45 +0200
Subject: [PATCH] records: Report unknown field names in inheriting forms.

* guix/records.scm (define-record-type*)[record-inheritance]: Check for
  unexpected field names.
* tests/records.scm ("define-record-type* with let* behavior"): Return
  #t, not *unspecified*.
  ("define-record-type* & inherit & extra initializers"): New test.
---
 guix/records.scm  |  8 ++++++++
 tests/records.scm | 17 ++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/guix/records.scm b/guix/records.scm
index e60732dd430..cd887b77ce9 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -69,6 +69,14 @@ (define (field-inherited-value f)
                                field+value)
                          car))
 
+                ;; Make sure there are no unknown field names.
+                (let* ((fields     (map (compose car syntax->datum)
+                                        field+value))
+                       (unexpected (lset-difference eq? fields 'expected)))
+                  (when (pair? unexpected)
+                    (record-error 'name s "extraneous field initializers ~a"
+                                  unexpected)))
+
                 #`(make-struct type 0
                                #,@(map (lambda (field index)
                                          (or (field-inherited-value field)
diff --git a/tests/records.scm b/tests/records.scm
index 23c0786e9ec..e90d33d15d7 100644
--- a/tests/records.scm
+++ b/tests/records.scm
@@ -58,7 +58,7 @@ (define-record-type* <bar> bar make-bar
          (match (bar (x 7) (z (* x 3)))
            (($ <bar> 7 42 21)))
          (match (bar (z 21) (x (/ z 3)))
-           (($ <bar> 7 42 21))))))
+           (($ <bar> 7 42 21) #t)))))
 
 (test-assert "define-record-type* & inherit"
   (begin
@@ -171,6 +171,21 @@ (define-record-type* <foo> foo make-foo
       (and (string-match "extra.*initializer.*baz" message)
            (eq? proc 'foo)))))
 
+(test-assert "define-record-type* & inherit & extra initializers"
+  (catch 'syntax-error
+    (lambda ()
+      (eval '(begin
+               (define-record-type* <foo> foo make-foo
+                 foo?
+                 (bar foo-bar (default 42)))
+
+               (foo (inherit (foo)) (baz 'what?)))
+            (test-module))
+      #f)
+    (lambda (key proc message location form . args)
+      (and (string-match "extra.*initializer.*baz" message)
+           (eq? proc 'foo)))))
+
 (test-equal "recutils->alist"
   '((("Name" . "foo")
      ("Version" . "0.1")
-- 
GitLab