1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-18 01:30:27 +02:00

Ensure macro-introduced top-level identifiers are unique

* module/ice-9/psyntax.scm (expand-top-sequence): When making a fresh
name for an introduced identifier, the hash isn't enough: it's quite
possible for normal programs to have colliding hash values, because
Guile's hash functions on pairs doesn't traverse the whole tree.
Therefore, append a uniquifying counter if the introduced name is
already defined in the current expansion unit.
* test-suite/tests/syntax.test ("duplicate top-level introduced
definitions"): Add test.
This commit is contained in:
Andy Wingo 2024-01-29 10:35:59 +01:00
parent 455ee49f55
commit 1349c41a60
2 changed files with 42 additions and 12 deletions

View file

@ -1,7 +1,7 @@
;;;; syntax.test --- test suite for Guile's syntactic forms -*- scheme -*-
;;;;
;;;; Copyright (C) 2001, 2003, 2004, 2005, 2006, 2009, 2010,
;;;; 2011, 2012, 2013, 2014, 2021 Free Software Foundation, Inc.
;;;; 2011, 2012, 2013, 2014, 2021, 2024 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@ -1695,6 +1695,18 @@
((_ x) (when (eq? x #nil) 42))))
(foo #nil))))
(with-test-prefix "duplicate top-level introduced definitions"
(pass-if-equal '(42 69)
(begin
(define-syntax-rule (defconst f val)
(begin
;; The zeros cause a hash collision.
(define t (begin 0 0 0 0 0 0 0 0 0 val))
(define (f) t)))
(defconst a 42)
(defconst b 69)
(list (a) (b)))))
;;; Local Variables:
;;; eval: (put 'pass-if-syntax-error 'scheme-indent-function 1)
;;; eval: (put 'with-ellipsis 'scheme-indent-function 1)