make provide/contract work properly when it is the only thing in a module body
closes PR 11596
This commit is contained in:
parent
8d7f29d0bb
commit
31a629ff9c
|
@ -123,7 +123,7 @@
|
||||||
;; delay expansion until it's a good time to lift expressions:
|
;; delay expansion until it's a good time to lift expressions:
|
||||||
(quasisyntax/loc stx (#%expression #,stx)))))))
|
(quasisyntax/loc stx (#%expression #,stx)))))))
|
||||||
|
|
||||||
(define-syntax (provide/contract provide-stx)
|
(define-for-syntax (true-provide/contract provide-stx)
|
||||||
(syntax-case provide-stx (struct)
|
(syntax-case provide-stx (struct)
|
||||||
[(_ p/c-ele ...)
|
[(_ p/c-ele ...)
|
||||||
(let ()
|
(let ()
|
||||||
|
@ -756,6 +756,22 @@
|
||||||
(begin
|
(begin
|
||||||
bodies ...))))]))
|
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)
|
(define (make-pc-struct-type struct-name struct:struct-name . ctcs)
|
||||||
(let-values ([(struct:struct-name _make _pred _get _set)
|
(let-values ([(struct:struct-name _make _pred _get _set)
|
||||||
(make-struct-type struct-name
|
(make-struct-type struct-name
|
||||||
|
|
|
@ -10925,6 +10925,22 @@ so that propagation occurs.
|
||||||
|
|
||||||
(contract-eval '(require 'provide/contract-35/n)))))
|
(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
|
(contract-error-test
|
||||||
#'(begin
|
#'(begin
|
||||||
(eval '(module pce1-bug scheme/base
|
(eval '(module pce1-bug scheme/base
|
||||||
|
|
Loading…
Reference in New Issue
Block a user