1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

srfi-35: Generate a unique binding for the constructor.

Previously we'd get warnings like:

  t.scm:11:0: warning: shadows previous definition of `unused-constructor-51900bdce47d50c' at /tmp/t.scm:6:0

whenever 'define-condition-type' appeared more than once in a source
file.

* module/srfi/srfi-35.scm (define-condition-type): Rewrite as
'syntax-case' and generate UNUSED-CONSTRUCTOR as a function of TYPE.
This commit is contained in:
Ludovic Courtès 2019-12-14 23:56:12 +01:00
parent 0b2ae37094
commit 76e436c892

View file

@ -118,11 +118,20 @@ by C."
(let ((pred (record-predicate type)))
(or-map (lambda (x) (and (pred x) x)) (simple-exceptions c))))
(define-syntax-rule (define-condition-type type parent predicate
(field accessor) ...)
(define-exception-type type parent
unused-constructor predicate
(field accessor) ...))
(define-syntax define-condition-type
(lambda (s)
(syntax-case s ()
((_ type parent predicate (field accessor) ...)
;; The constructor is unused, but generate a new name for each
;; condition to avoid '-Wshadowed-toplevel' warnings when several
;; condition types are defined in the same compilation unit.
(with-syntax ((unused-constructor
(datum->syntax
#'type
(symbol-append '#{ make-}# (syntax->datum #'type)))))
#'(define-exception-type type parent
unused-constructor predicate
(field accessor) ...))))))
(define-syntax condition-instantiation
;; Build the `(make-condition type ...)' call.