Skip to content

Commit 7ed3345

Browse files
committed
expand prefab types when printing them
closes #1041
1 parent f33abfd commit 7ed3345

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

typed-racket-lib/typed-racket/types/printer.rkt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"utils/tc-utils.rkt"
2323
"types/struct-table.rkt"
2424
"infer/infer.rkt"
25+
"env/type-name-env.rkt"
2526
"types/substitute.rkt")
2627
(for-syntax racket/base syntax/parse))
2728

@@ -573,10 +574,10 @@
573574
;; type->sexp : Type -> S-expression
574575
;; convert a type to an s-expression that can be printed
575576
(define (type->sexp type [ignored-names '()])
576-
(define (t->s type)
577+
(define (t->s type [ignored-names '()])
577578
(parameterize ([current-print-type-fuel
578579
(sub1 (current-print-type-fuel))])
579-
(type->sexp type)))
580+
(type->sexp type ignored-names)))
580581
(define (tuple? t)
581582
(match t
582583
[(Pair: a (? tuple?)) #t]
@@ -600,13 +601,16 @@
600601
[(Univ:) 'Any]
601602
[(Bottom:) 'Nothing]
602603
;; struct names are just printed as the original syntax
603-
[(Name/struct: id) (syntax-e id)]
604+
[(Name/struct: id)
605+
(match (lookup-type-name id (lambda () #f))
606+
[(and (? Prefab?) ty) (t->s ty (cons id ignored-names))]
607+
[_ (syntax-e id)])]
604608
;; If a type has a name, then print it with that name.
605609
;; However, we expand the alias in some cases
606610
;; (i.e., the fuel is > 0) for the :type form.
607611
[(app has-name? (? values names))
608612
(=> fail)
609-
(when (not (null? ignored-names)) (fail))
613+
(unless (null? ignored-names) (fail))
610614
(define fuel (current-print-type-fuel))
611615
(cond [(> fuel 0)
612616
(parameterize ([current-print-type-fuel (sub1 fuel)])
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#;
2+
(exn-pred #rx"expected: \\(Prefab container String\\).*given: \\(Prefab container Positive-Byte\\)")
3+
#lang typed/racket/base
4+
5+
(define val '#s(container 10))
6+
(struct container
7+
([value : String])
8+
#:prefab)
9+
(ann val container)
10+

0 commit comments

Comments
 (0)