From fea71732d2fa9ec1a61fd9f583622fb37b35edb6 Mon Sep 17 00:00:00 2001 From: Andrew Kent Date: Sat, 20 May 2017 19:22:05 +0100 Subject: [PATCH] fix intersection printing err (#551) --- typed-racket-lib/typed-racket/rep/type-rep.rkt | 10 +++------- typed-racket-lib/typed-racket/types/printer.rkt | 10 ++++++---- typed-racket-test/unit-tests/type-printer-tests.rkt | 4 +++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/typed-racket-lib/typed-racket/rep/type-rep.rkt b/typed-racket-lib/typed-racket/rep/type-rep.rkt index 08782155..80070632 100644 --- a/typed-racket-lib/typed-racket/rep/type-rep.rkt +++ b/typed-racket-lib/typed-racket/rep/type-rep.rkt @@ -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 diff --git a/typed-racket-lib/typed-racket/types/printer.rkt b/typed-racket-lib/typed-racket/types/printer.rkt index bab4d97f..0b886784 100644 --- a/typed-racket-lib/typed-racket/types/printer.rkt +++ b/typed-racket-lib/typed-racket/types/printer.rkt @@ -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] diff --git a/typed-racket-test/unit-tests/type-printer-tests.rkt b/typed-racket-test/unit-tests/type-printer-tests.rkt index b59af985..6c9ed1c8 100644 --- a/typed-racket-test/unit-tests/type-printer-tests.rkt +++ b/typed-racket-test/unit-tests/type-printer-tests.rkt @@ -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")