~ chicken-core (chicken-5) 721d8a592bb07c91eb093051d922c825b230a9b0
commit 721d8a592bb07c91eb093051d922c825b230a9b0 Author: Peter Bex <peter@more-magic.net> AuthorDate: Sun Oct 6 20:56:39 2019 +0200 Commit: Kooda <kooda@upyum.com> CommitDate: Fri Oct 11 16:33:45 2019 +0200 Check constructor args against field defs in define-record-type It's okay to have field definitions which don't show up in the constructor argument list (those will have an unspecified value according to the SRFI), but if there are arguments which don't correspond to any field (which SRFI-9 calls "<field tag>"), this is an error. We now actually signal an error to help the user spot typos. This fixes #1633 Signed-off-by: Kooda <kooda@upyum.com> diff --git a/NEWS b/NEWS index d2708547..64b8f6db 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,8 @@ C_i_check_exact_2 have been deprecated (see also #1631). - When garbage collector is manually invoked from a finalizer, raise an error instead of hanging forever (fixes #1586). + - define-record-type will now give an error if the constructor + definition refers to field that's not listed elsewhere (see #1633) - Compiler - Fixed a bug in lfa2 pass which caused "if" or "cond" nodes to be diff --git a/chicken-syntax.scm b/chicken-syntax.scm index e943222d..54609dac 100644 --- a/chicken-syntax.scm +++ b/chicken-syntax.scm @@ -1097,6 +1097,14 @@ (x (r 'x)) (y (r 'y)) (slotnames (map car slots))) + ;; Check for inconsistencies in slot names vs constructor args + (for-each (lambda (vname) + (unless (memq vname slotnames) + (syntax-error + 'define-record-type + "unknown slot name in constructor definition" + vname))) + vars) `(##core#begin ;; TODO: Maybe wrap this in an opaque object? (,%define ,type-name (##core#quote ,tag))Trap