Fill hole in recursive type soundness. Fixes PR 11372.

This commit is contained in:
Eric Dobson 2012-08-04 15:53:21 -07:00 committed by Vincent St-Amour
parent 9f453676d1
commit e6d4fb2ee2
2 changed files with 18 additions and 6 deletions

View File

@ -772,6 +772,11 @@
(if (number? x) (if (number? x)
(begin (f) (add1 x)) (begin (f) (add1 x))
12))] 12))]
[tc-err (ann 3 (Rec a a))]
[tc-err (ann 3 (Rec a (U a 3)))]
[tc-err (ann 3 (Rec a (Rec b a)))]
#; #;
[tc-err (lambda: ([x : Any]) [tc-err (lambda: ([x : Any])
(if (number? (not (not x))) (if (number? (not (not x)))

View File

@ -212,14 +212,21 @@
(extend-tvars (list var) (extend-tvars (list var)
(let ([t* (parse-type #'t)]) (let ([t* (parse-type #'t)])
;; is t in a productive position? ;; is t in a productive position?
(unless (match t* (define productive
[(Union: es) (let loop ((ty t*))
(define seq-tvar (Type-seq tvar)) (match ty
(not (memf (λ (e) (eq? (Type-seq e) seq-tvar)) es))] [(Union: elems) (andmap loop elems)]
[_ #t]) ; it's fine [(F: _) (not (equal? ty tvar))]
[(App: rator rands stx)
(loop (resolve-app rator rands stx))]
[(Mu: _ body) (loop body)]
[(Poly: names body) (loop body)]
[(PolyDots: names body) (loop body)]
[else #t])))
(unless productive
(tc-error/stx (tc-error/stx
stx stx
"Recursive types are not allowed as members of unions directly inside their definition")) "Recursive types are not allowed directly inside their definition"))
(if (memq var (fv t*)) (if (memq var (fv t*))
(make-Mu var t*) (make-Mu var t*)
t*))))] t*))))]