records: match-record: Raise a syntax error if TYPE is nonexistent.
* guix/records.scm (match-record): Raise a human-compherensible syntax error if the given record type identifier is unbound. Co-authored-by: Josselin Poiret <dev@jpoiret.xyz> Signed-off-by: Josselin Poiret <dev@jpoiret.xyz>master
parent
f72f3a909a
commit
1a4aace3af
|
@ -105,7 +105,12 @@ error-reporting purposes."
|
||||||
|
|
||||||
(define-syntax map-fields
|
(define-syntax map-fields
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(syntax-violation 'map-fields "bad use of syntactic keyword" x x)))
|
(syntax-case x ()
|
||||||
|
((_ type within)
|
||||||
|
(syntax-violation (syntax->datum #'within)
|
||||||
|
"undefined guix record-type"
|
||||||
|
#'type))
|
||||||
|
(_ (syntax-violation 'map-fields "bad use of syntactic keyword" x x)))))
|
||||||
|
|
||||||
(define-syntax-parameter this-record
|
(define-syntax-parameter this-record
|
||||||
(lambda (s)
|
(lambda (s)
|
||||||
|
@ -459,7 +464,7 @@ inherited."
|
||||||
"This macro lets us query record type info at
|
"This macro lets us query record type info at
|
||||||
macro-expansion time."
|
macro-expansion time."
|
||||||
(syntax-case s (map-fields)
|
(syntax-case s (map-fields)
|
||||||
((_ map-fields macro)
|
((_ (map-fields _ _) macro)
|
||||||
#'(macro (field ...)))
|
#'(macro (field ...)))
|
||||||
(id
|
(id
|
||||||
(identifier? #'id)
|
(identifier? #'id)
|
||||||
|
@ -595,7 +600,7 @@ found."
|
||||||
#'(let-syntax ((field-offset (syntax-rules ()
|
#'(let-syntax ((field-offset (syntax-rules ()
|
||||||
((_ f)
|
((_ f)
|
||||||
(lookup-field field 0 f)))))
|
(lookup-field field 0 f)))))
|
||||||
(let* ((offset (type map-fields field-offset))
|
(let* ((offset (type (map-fields type match-record) field-offset))
|
||||||
(variable (struct-ref record offset)))
|
(variable (struct-ref record offset)))
|
||||||
(match-record-inner record type (rest ...) body ...))))
|
(match-record-inner record type (rest ...) body ...))))
|
||||||
((_ record type (field rest ...) body ...)
|
((_ record type (field rest ...) body ...)
|
||||||
|
|
Reference in New Issue