diff --git a/typed-racket-lib/typed-racket/base-env/base-types-extra.rkt b/typed-racket-lib/typed-racket/base-env/base-types-extra.rkt index 12863d55..39a176bb 100644 --- a/typed-racket-lib/typed-racket/base-env/base-types-extra.rkt +++ b/typed-racket-lib/typed-racket/base-env/base-types-extra.rkt @@ -7,7 +7,12 @@ [(_ nm ...) #'(begin (define-syntax nm (lambda (stx) - (raise-syntax-error 'type-check "type name used out of context" + (raise-syntax-error 'type-check + (format "type name ~a used out of context in ~a" + (syntax->datum (if (stx-pair? stx) + (stx-car stx) + stx)) + (syntax->datum stx)) stx (and (stx-pair? stx) (stx-car stx))))) ... @@ -26,4 +31,3 @@ [List Tuple] [Rec mu] [Parameterof Parameter])) - diff --git a/typed-racket-lib/typed-racket/base-env/extra-env-lang.rkt b/typed-racket-lib/typed-racket/base-env/extra-env-lang.rkt index 99beef4a..7a6932f8 100644 --- a/typed-racket-lib/typed-racket/base-env/extra-env-lang.rkt +++ b/typed-racket-lib/typed-racket/base-env/extra-env-lang.rkt @@ -52,7 +52,11 @@ ;; lift out to utility module maybe (define-syntax (type stx) (raise-syntax-error 'type-check - "type name used out of context" + (format "type name ~a used out of context in ~a" + (syntax->datum (if (stx-pair? stx) + (stx-car stx) + stx)) + (syntax->datum stx)) stx (and (stx-pair? stx) (stx-car stx)))) (provide type pred)))) diff --git a/typed-racket-lib/typed-racket/base-env/prims-struct.rkt b/typed-racket-lib/typed-racket/base-env/prims-struct.rkt index 0263f795..7d6f8a39 100644 --- a/typed-racket-lib/typed-racket/base-env/prims-struct.rkt +++ b/typed-racket-lib/typed-racket/base-env/prims-struct.rkt @@ -197,7 +197,9 @@ #'(lambda (stx) (raise-syntax-error 'type-check - "type name used out of context" + (format "type name ~a used out of context in ~a" + (syntax->datum (if (stx-pair? stx) (stx-car stx) stx)) + (syntax->datum stx)) stx (and (stx-pair? stx) (stx-car stx))))) #`(begin diff --git a/typed-racket-lib/typed-racket/base-env/type-env-lang.rkt b/typed-racket-lib/typed-racket/base-env/type-env-lang.rkt index 1105dd7d..3f19eefa 100644 --- a/typed-racket-lib/typed-racket/base-env/type-env-lang.rkt +++ b/typed-racket-lib/typed-racket/base-env/type-env-lang.rkt @@ -9,7 +9,10 @@ (begin (define-syntax (nm stx) (raise-syntax-error - 'type-check "type name used out of context" + 'type-check + (format "type name ~a used out of context in ~a" + (syntax->datum (if (stx-pair? stx) (stx-car stx) stx)) + (syntax->datum stx)) stx (and (stx-pair? stx) (stx-car stx)))) ... diff --git a/typed-racket-lib/typed-racket/types/resolve.rkt b/typed-racket-lib/typed-racket/types/resolve.rkt index e507bd45..645be03f 100644 --- a/typed-racket-lib/typed-racket/types/resolve.rkt +++ b/typed-racket-lib/typed-racket/types/resolve.rkt @@ -43,8 +43,10 @@ (match rator [(Poly-unsafe: n _) (unless (= n (length rands)) - (tc-error "wrong number of arguments to polymorphic type: expected ~a and got ~a" - n (length rands)))] + (tc-error (~a "wrong number of arguments to polymorphic type " rator + ": expected " n + " and got " (length rands) + ", arguments were: " rands)))] [(Name/struct: n) (when (and (current-poly-struct) (free-identifier=? n (poly-name (current-poly-struct)))) @@ -61,7 +63,8 @@ " structure type constructor " rator " does not match the given number:" " expected " num-poly - ", given " num-rands))))] + ", given " num-rands + ", arguments were: " rands))))] [(Name: name-id num-args #f) (cond [(> num-args 0) (define num-rands (length rands)) @@ -69,7 +72,8 @@ (tc-error (~a "The expected number of arguments for " rator " does not match the given number:" " expected " num-args - ", given " num-rands))) + ", given " num-rands + ", arguments were: " rands))) ;; Does not allow polymorphic recursion since both type ;; inference and equirecursive subtyping for polymorphic ;; recursion are difficult. @@ -98,7 +102,8 @@ (not (member (syntax-e arg-name) (fv given-type))))) (unless ok? (tc-error (~a "Recursive type " rator " cannot be applied at" - " a different type in its recursive invocation")))) + " a different type in its recursive invocation," + " new arguments were: " rands)))) (match (current-check-polymorphic-recursion) [`#s(poly-rec-info ,same-component? ,current-vars) #:when (same-component? name-id) @@ -125,7 +130,8 @@ [(Poly: _ _) (instantiate-poly rator rands)] [(Mu: _ _) (resolve-app (unfold rator) rands stx)] [(App: r r* s) (resolve-app (resolve-app r r* s) rands stx)] - [_ (tc-error "cannot apply a non-polymorphic type: ~a" rator)]))) + [_ (tc-error (~a "cannot apply a non-polymorphic type: " rator + " with arguments: " rands))]))) (define (needs-resolving? t)