diff --git a/collects/mzlib/private/contract.ss b/collects/mzlib/private/contract.ss index 87ef7acab9..097744bec9 100644 --- a/collects/mzlib/private/contract.ss +++ b/collects/mzlib/private/contract.ss @@ -86,11 +86,11 @@ add struct contracts for immutable structs? [id id] [pos-module-source pos-module-source]) (syntax-case stx (set!) - [(set! _ body) (raise-syntax-error + [(set! id body) (raise-syntax-error #f "cannot set! provide/contract identifier" stx - (syntax _))] + (syntax id))] [(name arg ...) (syntax ((begin-lifted @@ -98,7 +98,7 @@ add struct contracts for immutable structs? id pos-module-source (module-source-as-symbol #'name) - (quote-syntax _))) + (quote-syntax name))) arg ...))] [name @@ -109,7 +109,7 @@ add struct contracts for immutable structs? id pos-module-source (module-source-as-symbol #'name) - (quote-syntax _))))]))))) + (quote-syntax name))))]))))) ;; (define/contract id contract expr) ;; defines `id' with `contract'; initially binding diff --git a/collects/tests/mzscheme/contract-test.ss b/collects/tests/mzscheme/contract-test.ss index 89e9164d29..6bbe96362a 100644 --- a/collects/tests/mzscheme/contract-test.ss +++ b/collects/tests/mzscheme/contract-test.ss @@ -4554,12 +4554,48 @@ #'(parameterize ([current-namespace (make-namespace)]) (eval '(module bug mzscheme (require (lib "contract.ss")) - (define the-defined-variable 'five) - (provide/contract [the-defined-variable number?]))) + (define the-defined-variable1 'five) + (provide/contract [the-defined-variable1 number?]))) (eval '(require bug))) (λ (x) (and (exn? x) - (regexp-match #rx"on the-defined-variable" (exn-message x))))) + (regexp-match #rx"on the-defined-variable1" (exn-message x))))) + + (error-test + #'(parameterize ([current-namespace (make-namespace)]) + (eval '(module bug mzscheme + (require (lib "contract.ss")) + (define the-defined-variable2 values) + (provide/contract [the-defined-variable2 (-> number? any)]))) + (eval '(require bug)) + (eval '(the-defined-variable2 #f))) + (λ (x) + (and (exn? x) + (regexp-match #rx"on the-defined-variable2" (exn-message x))))) + + (error-test + #'(parameterize ([current-namespace (make-namespace)]) + (eval '(module bug mzscheme + (require (lib "contract.ss")) + (define the-defined-variable3 (λ (x) #f)) + (provide/contract [the-defined-variable3 (-> any/c number?)]))) + (eval '(require bug)) + (eval '(the-defined-variable3 #f))) + (λ (x) + (and (exn? x) + (regexp-match #rx"on the-defined-variable3" (exn-message x))))) + + (error-test + #'(parameterize ([current-namespace (make-namespace)]) + (eval '(module bug mzscheme + (require (lib "contract.ss")) + (define the-defined-variable4 (λ (x) #f)) + (provide/contract [the-defined-variable4 (-> any/c number?)]))) + (eval '(require bug)) + (eval '((if #t the-defined-variable4) #f))) + (λ (x) + (and (exn? x) + (regexp-match #rx"on the-defined-variable4" (exn-message x)))))