From c07bd9c06707163d13c908afc9c8bfa165690920 Mon Sep 17 00:00:00 2001 From: Eric Dobson Date: Wed, 30 May 2012 20:57:31 -0700 Subject: [PATCH] Add support for multiple provides of the same identifier in TR. Closes PR 12807. original commit: 735b84b08310c44933cd5235719cb7f4a647a1c6 --- collects/tests/typed-racket/succeed/pr12807.rkt | 13 +++++++++++++ .../typed-racket/typecheck/provide-handling.rkt | 11 +++++++---- collects/typed-racket/typecheck/tc-toplevel.rkt | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 collects/tests/typed-racket/succeed/pr12807.rkt diff --git a/collects/tests/typed-racket/succeed/pr12807.rkt b/collects/tests/typed-racket/succeed/pr12807.rkt new file mode 100644 index 00000000..0e0095e1 --- /dev/null +++ b/collects/tests/typed-racket/succeed/pr12807.rkt @@ -0,0 +1,13 @@ +#lang racket/load +(module a typed/racket + (define (foo x) (list x)) + (provide + (rename-out (foo foo2)) + foo)) + +(module b racket + (require 'a) + (foo 2) + (foo2 3)) + +(require 'b) diff --git a/collects/typed-racket/typecheck/provide-handling.rkt b/collects/typed-racket/typecheck/provide-handling.rkt index ca048a4c..7813aa0c 100644 --- a/collects/typed-racket/typecheck/provide-handling.rkt +++ b/collects/typed-racket/typecheck/provide-handling.rkt @@ -31,7 +31,7 @@ (cond [(s:member i vd (lambda (i j) (free-identifier=? i (binding-name j)))) => car] [else #f])) -;; generate-contract-defs : dict[id -> def-binding] dict[id -> id] id -> syntax +;; generate-contract-defs : dict[id -> def-binding] dict[id -> list[id]] id -> syntax ;; defs: defines in this module ;; provs: provides in this module ;; pos-blame-id: a #%variable-reference for the module @@ -118,7 +118,10 @@ new-id))])] ;; otherwise, not defined in this module, not our problem [else (values #'(begin) internal-id)])) - ;; do-one : id id -> syntax - (for/list ([(internal-id external-id) (in-dict provs)]) + ;; Build the final provide with auxilliary definitions + (for/list ([(internal-id external-ids) (in-dict provs)]) (define-values (defs id) (mk internal-id)) - #`(begin #,defs (provide (rename-out [#,id #,external-id]))))) + (define provide-forms + (for/list ([external-id (in-list external-ids)]) + #`(rename-out [#,id #,external-id]))) + #`(begin #,defs (provide #,@provide-forms)))) diff --git a/collects/typed-racket/typecheck/tc-toplevel.rkt b/collects/typed-racket/typecheck/tc-toplevel.rkt index 1355ca55..9b89c9eb 100644 --- a/collects/typed-racket/typecheck/tc-toplevel.rkt +++ b/collects/typed-racket/typecheck/tc-toplevel.rkt @@ -305,11 +305,11 @@ [i:id (when (def-stx-binding? (dict-ref def-tbl #'i #f)) (set! syntax-provide? #t)) - (dict-set h #'i #'i)] + (dict-update h #'i (lambda (tail) (cons #'i tail)) '())] [((~datum rename) in out) (when (def-stx-binding? (dict-ref def-tbl #'in #f)) (set! syntax-provide? #t)) - (dict-set h #'in #'out)] + (dict-update h #'in (lambda (tail) (cons #'out tail)) '())] [(name:unknown-provide-form . _) (tc-error "provide: ~a not supported by Typed Racket" (syntax-e #'name.name))] [_ (int-err "unknown provide form")])))]