make provide/contract work properly when it is the only thing in a module body

closes PR 11596
This commit is contained in:
Robby Findler 2011-01-07 05:15:26 -06:00
parent 8d7f29d0bb
commit 31a629ff9c
2 changed files with 33 additions and 1 deletions

View File

@ -123,7 +123,7 @@
;; delay expansion until it's a good time to lift expressions:
(quasisyntax/loc stx (#%expression #,stx)))))))
(define-syntax (provide/contract provide-stx)
(define-for-syntax (true-provide/contract provide-stx)
(syntax-case provide-stx (struct)
[(_ p/c-ele ...)
(let ()
@ -756,6 +756,22 @@
(begin
bodies ...))))]))
(define-syntax (provide/contract stx)
(define s-l-c (syntax-local-context))
(case s-l-c
[(module-begin) ;; the case under discussion
#`(begin (define-values () (values)) ;; force us into the 'module' local context
#,stx)]
[(module) ;; the good case
(true-provide/contract stx)]
[else ;; expression or internal definition
(raise-syntax-error 'provide/contract
(format "not allowed in a ~a context"
(if (pair? s-l-c)
"internal definition"
s-l-c))
stx)]))
(define (make-pc-struct-type struct-name struct:struct-name . ctcs)
(let-values ([(struct:struct-name _make _pred _get _set)
(make-struct-type struct-name

View File

@ -10925,6 +10925,22 @@ so that propagation occurs.
(contract-eval '(require 'provide/contract-35/n)))))
;; test that provide/contract by itself in a module doesn't signal an error
(test/spec-passed/result
'provide/contract35
'(begin
(eval '(module provide/contract35-m1 racket
(provide/contract [add1 (-> number? number?)])))
(eval '(module provide/contract35-m2 racket/base
(require 'provide/contract35-m1)
(provide provide/contract35-three)
(define provide/contract35-three (add1 2))))
(eval '(require 'provide/contract35-m2))
(eval 'provide/contract35-three))
3)
(contract-error-test
#'(begin
(eval '(module pce1-bug scheme/base