diff --git a/pkgs/racket-test-core/tests/racket/pretty.rktl b/pkgs/racket-test-core/tests/racket/pretty.rktl index 48b19f1f42..347f418a0e 100644 --- a/pkgs/racket-test-core/tests/racket/pretty.rktl +++ b/pkgs/racket-test-core/tests/racket/pretty.rktl @@ -447,6 +447,20 @@ (test "#true" pretty-format #t) (test "#false" pretty-format #f)) +;; ---------------------------------------- +;; check that an all-powerful inspector doesn't break the pretty printer internally + +(let-values ([(pp v) + (parameterize ([current-namespace (make-base-namespace)] + [current-inspector (make-inspector)]) + (define pp (dynamic-require 'racket/pretty 'pretty-print)) + (struct a (x)) + (values pp (a 1)))]) + (define o (open-output-bytes)) + (parameterize ([current-output-port o]) + (pp v)) + (test "(a 1)\n" get-output-string o)) + ;; ---------------------------------------- (report-errs) diff --git a/racket/collects/racket/pretty.rkt b/racket/collects/racket/pretty.rkt index 6009ecc9db..13ff22ec0e 100644 --- a/racket/collects/racket/pretty.rkt +++ b/racket/collects/racket/pretty.rkt @@ -913,7 +913,11 @@ qd (to-quoted out qd obj)))]) (write-custom wr* obj pport depth display? width qd #f)))))] - [(struct? obj) + [(hide? obj) + (wr* pport (hide-val obj) depth display? qd)] + [(unquoted? obj) + (orig-write (unquoted-val obj) pport)] + [(struct? obj) (if (and print-struct? (not (and depth (zero? depth)))) @@ -959,8 +963,6 @@ pair? car cdr "(" ")" qd)))) (parameterize ([print-hash-table #f]) ((if display? orig-display orig-write) obj pport)))] - [(hide? obj) - (wr* pport (hide-val obj) depth display? qd)] [(boolean? obj) (out (if long-bools? (if obj "#true" "#false") @@ -973,7 +975,7 @@ number->decimal-string number->string) obj))] - [(and (pretty-print-.-symbol-without-bars) + [(and (pretty-print-.-symbol-without-bars) (eq? obj '|.|)) (out ".")] [(and qd (or (symbol? obj) @@ -981,8 +983,6 @@ (unless (eq? obj struct-ellipses) (to-quoted out qd obj)) (orig-write obj pport)] - [(unquoted? obj) - (orig-write (unquoted-val obj) pport)] [else ((if display? orig-display orig-write) obj pport)])) (unless (hide? obj)