From 350a8bb74ec9fe83a3edda6c58e5043897e977f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 30 Dec 2015 19:34:43 +0100 Subject: [PATCH] Changed how arguments and other pieces of information are printed, to follow the error message conventions, as suggested by samth in PR #250 . * PR #250: https://github.com/racket/typed-racket/pull/250 * Error message conventions: http://docs.racket-lang.org/reference/exns.html?q=raise-arg#%28part._err-msg-conventions%29 --- .../base-env/base-types-extra.rkt | 2 +- .../typed-racket/base-env/extra-env-lang.rkt | 2 +- .../typed-racket/base-env/prims-struct.rkt | 2 +- .../typed-racket/base-env/type-env-lang.rkt | 2 +- .../typed-racket/types/resolve.rkt | 57 +++++++++++-------- typed-racket-test/fail/pr13209.rkt | 2 +- .../fail/recursive-type-application.rkt | 2 +- 7 files changed, 39 insertions(+), 30 deletions(-) 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 39a176bb..1376d537 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 @@ -8,7 +8,7 @@ #'(begin (define-syntax nm (lambda (stx) (raise-syntax-error 'type-check - (format "type name ~a used out of context in ~a" + (format "type name used out of context\n type: ~a\n in: ~a" (syntax->datum (if (stx-pair? stx) (stx-car stx) stx)) 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 7a6932f8..5ae76534 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,7 @@ ;; lift out to utility module maybe (define-syntax (type stx) (raise-syntax-error 'type-check - (format "type name ~a used out of context in ~a" + (format "type name used out of context\n type: ~a\n in: ~a" (syntax->datum (if (stx-pair? stx) (stx-car stx) stx)) 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 d0c918fe..22c39366 100644 --- a/typed-racket-lib/typed-racket/base-env/prims-struct.rkt +++ b/typed-racket-lib/typed-racket/base-env/prims-struct.rkt @@ -235,7 +235,7 @@ #'(lambda (stx) (raise-syntax-error 'type-check - (format "type name ~a used out of context in ~a" + (format "type name used out of context\n type: ~a\n in: ~a" (syntax->datum (if (stx-pair? stx) (stx-car stx) stx)) (syntax->datum stx)) stx 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 3f19eefa..973ba05e 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 @@ -10,7 +10,7 @@ (define-syntax (nm stx) (raise-syntax-error 'type-check - (format "type name ~a used out of context in ~a" + (format "type name used out of context\n type: ~a\n in: ~a" (syntax->datum (if (stx-pair? stx) (stx-car stx) stx)) (syntax->datum stx)) stx diff --git a/typed-racket-lib/typed-racket/types/resolve.rkt b/typed-racket-lib/typed-racket/types/resolve.rkt index 645be03f..1d79a291 100644 --- a/typed-racket-lib/typed-racket/types/resolve.rkt +++ b/typed-racket-lib/typed-racket/types/resolve.rkt @@ -43,10 +43,11 @@ (match rator [(Poly-unsafe: n _) (unless (= n (length rands)) - (tc-error (~a "wrong number of arguments to polymorphic type " rator - ": expected " n - " and got " (length rands) - ", arguments were: " rands)))] + (tc-error (~a "wrong number of arguments to polymorphic type" + "\n type: " rator + "\n expected: " n + "\n given: " (length rands) + "\n arguments...: " rands)))] [(Name/struct: n) (when (and (current-poly-struct) (free-identifier=? n (poly-name (current-poly-struct)))) @@ -57,23 +58,23 @@ (when (not (or (ormap Error? rands) (andmap type-equal? rands (poly-vars (current-poly-struct))))) - (tc-error (~a "Structure type constructor " rator - " applied to non-regular arguments " rands))) - (tc-error (~a "The expected number of arguments for" - " structure type constructor " rator - " does not match the given number:" - " expected " num-poly - ", given " num-rands - ", arguments were: " rands))))] + (tc-error (~a "structure type constructor applied to non-regular arguments" + "\n type: " rator + "\n arguments...: " rands))) + (tc-error (~a "wrong number of arguments to structure type constructor" + "\n type: " rator + "\n expected: " num-poly + "\n given: " num-rands + "\n arguments...: " rands))))] [(Name: name-id num-args #f) (cond [(> num-args 0) (define num-rands (length rands)) (unless (= num-rands num-args) - (tc-error (~a "The expected number of arguments for " - rator " does not match the given number:" - " expected " num-args - ", given " num-rands - ", arguments were: " rands))) + (tc-error (~a "wrong number of arguments to polymorphic type" + "\n type: " rator + "\n expected: " num-args + "\n given: " num-rands + "\n arguments...: " rands))) ;; Does not allow polymorphic recursion since both type ;; inference and equirecursive subtyping for polymorphic ;; recursion are difficult. @@ -101,9 +102,12 @@ (or (F? given-type) (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," - " new arguments were: " rands)))) + (tc-error (~a "recursive type cannot be applied at a" + " different type in its recursive invocation" + "\n type: " rator + "\n new argument name: " arg-name + "\n new argument: " given-type + "\n new arguments...: " rands)))) (match (current-check-polymorphic-recursion) [`#s(poly-rec-info ,same-component? ,current-vars) #:when (same-component? name-id) @@ -112,11 +116,15 @@ (check-argument rand var))] [_ (void)])] [else - (tc-error "Type ~a cannot be applied, arguments were: ~a" rator rands)])] + (tc-error (~a "type cannot be applied" + "\n type: " rator + "\n arguments...: " rands))])] [(Mu: _ _) (void)] [(App: _ _ _) (void)] [(Error:) (void)] - [_ (tc-error/delayed "Type ~a cannot be applied, arguments were: ~a" rator rands)]))) + [_ (tc-error/delayed (~a "type cannot be applied" + "\n type: " rator + "\n arguments...: " rands))]))) (define (resolve-app rator rands stx) @@ -130,8 +138,9 @@ [(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 (~a "cannot apply a non-polymorphic type: " rator - " with arguments: " rands))]))) + [_ (tc-error (~a "cannot apply a non-polymorphic type" + "\n type: " rator + "\n arguments: " rands))]))) (define (needs-resolving? t) diff --git a/typed-racket-test/fail/pr13209.rkt b/typed-racket-test/fail/pr13209.rkt index 78a9aee7..9bba8b82 100644 --- a/typed-racket-test/fail/pr13209.rkt +++ b/typed-racket-test/fail/pr13209.rkt @@ -1,5 +1,5 @@ #; -(exn-pred #rx"arguments for structure type constructor") +(exn-pred #rx"wrong number of arguments to structure type constructor") #lang typed/racket ;; Test for PR 13209 diff --git a/typed-racket-test/fail/recursive-type-application.rkt b/typed-racket-test/fail/recursive-type-application.rkt index 4e211002..c5371836 100644 --- a/typed-racket-test/fail/recursive-type-application.rkt +++ b/typed-racket-test/fail/recursive-type-application.rkt @@ -1,5 +1,5 @@ #; -(exn-pred #rx"does not match the given number:") +(exn-pred #rx"wrong number of arguments to polymorphic type") #lang typed/racket ;; Check bad arity for recursive invocation of Foo