From 7606cb342a09abb3f0c5798136811f65e736339b Mon Sep 17 00:00:00 2001
From: Peter Bex
Date: Sun, 6 Oct 2019 20:56:39 +0200
Subject: [PATCH] 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 ""), this is an
error. We now actually signal an error to help the user spot typos.
This fixes #1633
---
NEWS | 2 ++
chicken-syntax.scm | 8 ++++++++
2 files changed, 10 insertions(+)
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))
--
2.20.1