From 6e94295c9679603eda6ae88d44b9bdcc2ed94faa Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Mon, 20 May 2013 16:14:23 -0400 Subject: [PATCH] Add a #:verbose option to :type. This prints the old way, expanding all aliases inside the type. (cherry picked from commit 1f5b262f6d5c048bf546e7b048ab342de29b27d7) --- .../succeed/type-printer-single-level.rkt | 13 +++++++++++++ collects/typed-racket/core.rkt | 12 ++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/collects/tests/typed-racket/succeed/type-printer-single-level.rkt b/collects/tests/typed-racket/succeed/type-printer-single-level.rkt index 4cbe08c8de..9bc5d19b04 100644 --- a/collects/tests/typed-racket/succeed/type-printer-single-level.rkt +++ b/collects/tests/typed-racket/succeed/type-printer-single-level.rkt @@ -21,3 +21,16 @@ (tr-eval '(:type Bar)) (check-equal? (get-output-string out) "(U Integer String)\n(Foo -> Foo)\n") + +;; if #:verbose, make sure it's the full type +(tr-eval '(:type #:verbose Bar)) +(check-equal? (get-output-string out) + (string-append "(U Integer String)\n(Foo -> Foo)\n" + "((U 0 1 Byte-Larger-Than-One Positive-Index-Not-Byte " + "Positive-Fixnum-Not-Index Negative-Fixnum " + "Positive-Integer-Not-Fixnum Negative-Integer-Not-Fixnum String) " + "-> (U 0 1 Byte-Larger-Than-One Positive-Index-Not-Byte " + "Positive-Fixnum-Not-Index Negative-Fixnum " + "Positive-Integer-Not-Fixnum Negative-Integer-Not-Fixnum " + "String))\n")) + diff --git a/collects/typed-racket/core.rkt b/collects/typed-racket/core.rkt index fb77967fe8..34cf8f1e17 100644 --- a/collects/typed-racket/core.rkt +++ b/collects/typed-racket/core.rkt @@ -53,8 +53,16 @@ (syntax-parse stx [(_ . ((~datum module) . rest)) #'(module . rest)] - [(_ . ((~literal :type) ty:expr)) - (parameterize ([current-print-type-fuel 1]) + [(_ . ((~literal :type) + (~optional (~and #:verbose verbose-kw)) + ty:expr)) + (parameterize ([current-print-type-fuel + (if (attribute verbose-kw) +inf.0 1)] + ;; This makes sure unions are totally flat for the + ;; infinite fuel case. If fuel that's not 0, 1, or +inf.0 + ;; is ever used, more may need to be done. + [current-type-names + (if (attribute verbose-kw) '() (current-type-names))]) #`(display #,(format "~a\n" (parse-type #'ty))))] ;; Prints the _entire_ type. May be quite large. [(_ . ((~literal :print-type) e:expr))