From d62eedaa47b66dc2a804539c3c78b9f313a9243f Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Mon, 3 Mar 2014 17:59:55 -0500 Subject: [PATCH] Change TR's "untyped identifier" error messages --- .../typed-racket/types/tc-error.rkt | 30 ++++++++++++++----- .../tests/typed-racket/fail/untyped-srfi1.rkt | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/tc-error.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/tc-error.rkt index d0969109b2..f39c0e97b7 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/tc-error.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/tc-error.rkt @@ -36,15 +36,31 @@ ;; error for unbound variables (define (lookup-fail e) (match (identifier-binding e) - ['lexical (tc-error/expr "untyped identifier ~a" (syntax-e e))] + ['lexical (tc-error/expr/fields "missing type for identifier" + #:more "consider adding a type annotation with `:'" + "identifier" (syntax-e e))] [#f (tc-error/expr "untyped top-level identifier ~a" (syntax-e e))] [(list _ _ nominal-source-mod nominal-source-id _ _ _) - (let-values ([(x y) (module-path-index-split nominal-source-mod)]) - (cond [(and (not x) (not y)) - (tc-error/expr "untyped identifier ~a" (syntax-e e))] - [else - (tc-error/expr "untyped identifier ~a imported from module <~a>" - (syntax-e e) x)]))])) + (define-values (mod-path base-path) + (module-path-index-split nominal-source-mod)) + (cond [(and (not mod-path) (not base-path)) + (tc-error/expr/fields "missing type for identifier" + #:more "consider adding a type annotation with `:'" + "identifier" (syntax-e e))] + [(equal? mod-path '(lib "typed/racket")) + (tc-error/expr/fields + "missing type for identifier" + #:more + (string-append "The `racket' language does not seem" + " to have a type for this identifier;" + " please file a bug report") + "identifier" (syntax-e e) + "from module" mod-path)] + [else + (tc-error/expr/fields "missing type for identifier" + #:more "consider using `require/typed' to import it" + "identifier" (syntax-e e) + "from module" mod-path)])])) (define (lookup-type-fail i) (tc-error/expr "~a is not bound as a type" (syntax-e i))) diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/untyped-srfi1.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/untyped-srfi1.rkt index 3a4ec74c09..d1cf41337e 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/untyped-srfi1.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/untyped-srfi1.rkt @@ -1,5 +1,5 @@ #; -(exn-pred ".*untyped identifier map.*" ".*srfi.*") +(exn-pred ".*identifier: map.*" ".*srfi.*") #lang typed-scheme (require srfi/1)