Skip to content

Commit

Permalink
Add a #:verbose option to :type.
Browse files Browse the repository at this point in the history
This prints the old way, expanding all aliases inside the type.
  • Loading branch information
takikawa committed May 20, 2013
1 parent fd33584 commit 1f5b262
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 13 additions & 0 deletions collects/tests/typed-racket/succeed/type-printer-single-level.rkt
Expand Up @@ -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"))

12 changes: 10 additions & 2 deletions collects/typed-racket/core.rkt
Expand Up @@ -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))
Expand Down

0 comments on commit 1f5b262

Please sign in to comment.