From f0e22ae62c143fbf00bde368c2adbc848cff5ff5 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 23 Mar 2026 21:29:21 +0100 Subject: records: Warn about shadowing due to inherited field value bindings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a followup to a7c8e68dc51144a6d3981b770aca9c4897fc7c0c: this commit introduced a new binding in the body of field values, which could silently shadow outer bindings. This new warning catches potentially unwanted shadowing. * guix/records.scm (make-syntactic-constructor)[check-shadowing]: New procedure. [wrap-field-value]: Use it. * tests/records.scm ("define-record-type* & inherited value shadowing"): New test. Change-Id: I81ad14cf10da7213e9f8db987c8b0bd4c41acba2 Signed-off-by: Ludovic Courtès Merges: #7424 --- tests/records.scm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/records.scm b/tests/records.scm index 9c071334d50..57a21d2effc 100644 --- a/tests/records.scm +++ b/tests/records.scm @@ -302,6 +302,26 @@ => (,(foo-bar child) ,(foo-baz child)))))) +(test-assert "define-record-type* & inherited value shadowing" + (let ((exp '(begin + (define-record-type* foo make-foo + foo? + (bar foo-bar) + (baz foo-baz (thunked))) + + (let ((x (foo (bar 1) (baz 2))) + (baz 123)) + ;; Below, the 'baz' binding for the inherited field value + ;; shadows the 'baz' above, which should trigger a warning. + (foo (inherit x) + (baz (* baz 2))))))) + (string-contains + (call-with-output-string + (lambda (port) + (parameterize ((current-warning-port port)) + (eval exp (test-module))))) + "shadows local variable"))) + (test-assert "define-record-type* & delayed" (begin (define-record-type* foo make-foo -- cgit v1.3