mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 21:38:07 -05:00
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.
This commit is contained in:
parent
b1353e7a6b
commit
a1906758c3
2 changed files with 24 additions and 1 deletions
|
@ -69,6 +69,14 @@ (define (field-inherited-value f)
|
||||||
field+value)
|
field+value)
|
||||||
car))
|
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
|
#`(make-struct type 0
|
||||||
#,@(map (lambda (field index)
|
#,@(map (lambda (field index)
|
||||||
(or (field-inherited-value field)
|
(or (field-inherited-value field)
|
||||||
|
|
|
@ -58,7 +58,7 @@ (define-record-type* <bar> bar make-bar
|
||||||
(match (bar (x 7) (z (* x 3)))
|
(match (bar (x 7) (z (* x 3)))
|
||||||
(($ <bar> 7 42 21)))
|
(($ <bar> 7 42 21)))
|
||||||
(match (bar (z 21) (x (/ z 3)))
|
(match (bar (z 21) (x (/ z 3)))
|
||||||
(($ <bar> 7 42 21))))))
|
(($ <bar> 7 42 21) #t)))))
|
||||||
|
|
||||||
(test-assert "define-record-type* & inherit"
|
(test-assert "define-record-type* & inherit"
|
||||||
(begin
|
(begin
|
||||||
|
@ -171,6 +171,21 @@ (define-record-type* <foo> foo make-foo
|
||||||
(and (string-match "extra.*initializer.*baz" message)
|
(and (string-match "extra.*initializer.*baz" message)
|
||||||
(eq? proc 'foo)))))
|
(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"
|
(test-equal "recutils->alist"
|
||||||
'((("Name" . "foo")
|
'((("Name" . "foo")
|
||||||
("Version" . "0.1")
|
("Version" . "0.1")
|
||||||
|
|
Loading…
Reference in a new issue