fix intersection printing err (#551)

This commit is contained in:
Andrew Kent 2017-05-20 19:22:05 +01:00 committed by GitHub
parent 076b16bdf0
commit fea71732d2
3 changed files with 12 additions and 12 deletions

View File

@ -801,7 +801,7 @@
intersection-table
elems
prop
#:construct (make-Intersection ts prop elems))])
#:construct (make-Intersection (remove-duplicates ts) prop elems))])
(define intersection-table (make-weak-hash))
@ -825,7 +825,7 @@
[(list)
(match ts
[(list) (-refine Univ prop)]
[(list t) (-refine (car ts) prop)]
[(list t) (-refine t prop)]
[_ (let ([t (make-Intersection ts -tt elems)])
(-refine t prop))])]
[(cons arg args)
@ -840,11 +840,7 @@
[_ #:when (for/or ([elem (in-list args)])
(not (overlap? elem arg)))
-Bottom]
[t (let ([count (hash-count elems)]
[elems (hash-set elems t #t)])
(if (eqv? count (hash-count elems))
(loop ts elems prop args)
(loop (cons t ts) elems prop args)))])]))]))
[t (loop (cons t ts) (hash-set elems t #t) prop args)])]))]))
(define/provide (Intersection-w/o-prop t)
(match t

View File

@ -515,10 +515,6 @@
(set-box! (current-print-unexpanded)
(cons (car names) (unbox (current-print-unexpanded)))))
(car names)])]
;; format as a string to preserve reader abbreviations and primitive
;; values like characters (when `display`ed)
[(Val-able: v) (format "~v" v)]
[(? Base?) (Base-name type)]
[(StructType: (Struct: nm _ _ _ _ _)) `(StructType ,(syntax-e nm))]
;; this case occurs if the contained type is a type variable
[(StructType: ty) `(Struct-Type ,(t->s ty))]
@ -585,6 +581,12 @@
`(Refine [,(name-ref->sexp x) : ,ty] ,(prop->sexp prop))]
[(Intersection: elems _)
(cons ' (sort (map t->s elems) primitive<=?))]
;; format as a string to preserve reader abbreviations and primitive
;; values like characters (when `display`ed)
;; (comes after Intersection since Val-able will match
;; when an element of an intersection is a val)
[(Val-able: v) (format "~v" v)]
[(? Base?) (Base-name type)]
[(Pair: l r) `(Pairof ,(t->s l) ,(t->s r))]
[(ListDots: dty dbound) `(List ,(t->s dty) ... ,dbound)]
[(F: nm) nm]

View File

@ -222,7 +222,9 @@
(λ (str) (match (read (open-input-string str))
[`(Refine [,x : Integer] (or (: y Integer) (: z String))) #t]
[`(Refine [,x : Integer] (or (: z String) (: y Integer))) #t]
[_ #f]))))
[_ #f])))
(check-prints-as? (-unsafe-intersect (-val 2) (-v A)) "(∩ 2 A)"))
(test-suite
"Pretty printing tests"
(check-pretty-prints-as? (-val 3) "3")