diff --git a/typed-racket-doc/typed-racket/scribblings/reference/exploring-types.scrbl b/typed-racket-doc/typed-racket/scribblings/reference/exploring-types.scrbl index 0fd13910..5ea93404 100644 --- a/typed-racket-doc/typed-racket/scribblings/reference/exploring-types.scrbl +++ b/typed-racket-doc/typed-racket/scribblings/reference/exploring-types.scrbl @@ -33,7 +33,8 @@ The following bindings are only available at the Typed Racket REPL. ] } -@defform[(:print-type e)]{Prints the type of @racket[_e]. This prints the whole +@defform[(:print-type e)]{Prints the type of @racket[_e], which must be +an expression. This prints the whole type, which can sometimes be quite large. @examples[#:eval the-top-eval diff --git a/typed-racket-lib/typed-racket/base-env/top-interaction.rkt b/typed-racket-lib/typed-racket/base-env/top-interaction.rkt index 471b50e2..d758dbab 100644 --- a/typed-racket-lib/typed-racket/base-env/top-interaction.rkt +++ b/typed-racket-lib/typed-racket/base-env/top-interaction.rkt @@ -43,7 +43,7 @@ "../tc-setup.rkt" (private parse-type syntax-properties) (types utils abbrev printer) - (typecheck tc-toplevel tc-app-helper) + (typecheck tc-app-helper typechecker) (rep type-rep) (utils tc-utils) (for-template racket/base)) @@ -77,16 +77,16 @@ (define (:print-type-impl stx) (syntax-parse stx [(_ e) - (tc-toplevel/full stx #'e - (λ (expanded type) - #`(displayln - #,(if (eq? type 'no-type) - "This form has no type (it does not produce a value)." - (pretty-format-type - (match type - [(tc-result1: t f o) t] - [(tc-results: t) (-values t)] - [(tc-any-results: f) (-AnyValues f)]))))))] + (define type + (tc-expr (local-expand #'e 'expression (list #'module*)))) + #`(displayln + #,(if (eq? type 'no-type) + "This form has no type (it does not produce a value)." + (pretty-format-type + (match type + [(tc-result1: t f o) t] + [(tc-results: t) (-values t)] + [(tc-any-results: f) (-AnyValues f)]))))] [form (raise-syntax-error #f "must be applied to exactly one argument" #'form)])) @@ -95,17 +95,17 @@ (syntax-parse stx [(_ op arg-type ...) (with-syntax ([(dummy-arg ...) (generate-temporaries #'(arg-type ...))]) - (tc-toplevel/full - stx - ;; create a dummy function with the right argument types + ;; create a dummy function with the right argument types + (define expr #`(lambda #,(stx-map type-label-property #'(dummy-arg ...) #'(arg-type ...)) - (op dummy-arg ...)) - (λ (expanded type) - #`(display - #,(pretty-format-type - (match type - [(tc-result1: (and t (Function: _)) f o) t]))))))] + (op dummy-arg ...))) + (define type + (tc-expr (local-expand expr 'expression (list #'module*)))) + #`(display + #,(pretty-format-type + (match type + [(tc-result1: (and t (Function: _)) f o) t]))))] [form (raise-syntax-error #f "must be applied to at least one argument" #'form)])) @@ -114,17 +114,17 @@ (syntax-parse stx [(_ op desired-type) (let ([expected (parse-type #'desired-type)]) - (tc-toplevel/full stx #'op - (λ (expanded type) - (match type - [(tc-result1: (and t (Function: _)) f o) - (let ([cleaned (cleanup-type t expected #f)]) - #`(display - #,(match cleaned - [(Function: '()) - "Desired return type not in the given function's range.\n"] - [(Function: arrs) - (pretty-format-type cleaned)])))] - [_ (error (format "~a: not a function" (syntax->datum #'op)))]))))] + (define type + (tc-expr (local-expand #'op 'expression (list #'module*)))) + (match type + [(tc-result1: (and t (Function: _)) f o) + (let ([cleaned (cleanup-type t expected #f)]) + #`(display + #,(match cleaned + [(Function: '()) + "Desired return type not in the given function's range.\n"] + [(Function: arrs) + (pretty-format-type cleaned)])))] + [_ (error (format "~a: not a function" (syntax->datum #'op)))]))] [form (raise-syntax-error #f "must be applied to exactly two arguments" #'form)]))) diff --git a/typed-racket-test/unit-tests/interactive-tests.rkt b/typed-racket-test/unit-tests/interactive-tests.rkt index 16c77c7e..0cd3cc7e 100644 --- a/typed-racket-test/unit-tests/interactive-tests.rkt +++ b/typed-racket-test/unit-tests/interactive-tests.rkt @@ -152,10 +152,6 @@ (:print-type)) (test-form-exn #rx"exactly one argument" (:print-type 1 2)) - (test-form (regexp-quote "has no type") - (:print-type (begin (begin)))) - (test-form (regexp-quote "has no type") - (:print-type (require racket/format))) (test-form (regexp-quote "(-> 4 Zero Zero)") (:query-type/args * 4 0))