Fix printing for certain list types with a mu var

Closes PR 14552
This commit is contained in:
Asumu Takikawa 2014-06-09 13:35:06 -04:00
parent f90bf5e43b
commit bbc6a6b42d
3 changed files with 16 additions and 6 deletions

View File

@ -48,10 +48,10 @@
(define-match-expander MListof:
(lambda (stx)
(syntax-parse stx
[(_ elem-pat)
[(_ elem-pat (~optional var-pat #:defaults ([var-pat #'var])))
;; see note above
#'(or (Mu: var (Union: (list (Value: '()) (MPair: elem-pat (F: var)))))
(Mu: var (Union: (list (MPair: elem-pat (F: var)) (Value: '())))))])))
#'(or (Mu: var-pat (Union: (list (Value: '()) (MPair: elem-pat (F: var-pat)))))
(Mu: var-pat (Union: (list (MPair: elem-pat (F: var-pat)) (Value: '())))))])))
(define (unpoly t)
(match t

View File

@ -432,10 +432,14 @@
[(Continuation-Mark-KeyTop:) 'Continuation-Mark-KeyTop]
[(App: rator rands stx)
(list* (type->sexp rator) (map type->sexp rands))]
;; special cases for lists
[(Listof: elem-ty)
;; Special cases for lists. Avoid printing with these cases if the
;; element type refers to the Mu variable (otherwise it prints the
;; type variable with no binding).
[(Listof: elem-ty var)
#:when (not (memq var (fv elem-ty)))
`(Listof ,(t->s elem-ty))]
[(MListof: elem-ty)
[(MListof: elem-ty var)
#:when (not (memq var (fv elem-ty)))
`(MListof ,(t->s elem-ty))]
;; format as a string to preserve reader abbreviations and primitive
;; values like characters (when `display`ed)

View File

@ -47,6 +47,12 @@
(check-prints-as? (make-Mu 'x (Un -Null (-pair -Nat (make-F 'x))))
"(Listof Nonnegative-Integer)")
(check-prints-as? (-lst* -String -Symbol) "(List String Symbol)")
;; next three cases for PR 14552
(check-prints-as? (-mu x (Un (-pair x x) -Null)) "(Rec x (U Null (Pairof x x)))")
(check-prints-as? (-mu x (Un (-pair (-box x) x) -Null)) "(Rec x (U Null (Pairof (Boxof x) x)))")
(check-prints-as? (-mu x (Un (-mpair x x) -Null)) "(Rec x (U Null (MPairof x x)))")
(check-prints-as? -Custodian "Custodian")
(check-prints-as? (make-Opaque #'integer?) "(Opaque integer?)")
(check-prints-as? (make-Vector -Nat) "(Vectorof Nonnegative-Integer)")