From 898c92eb1e6b476a8511d4d4be2e9b962e147d5e Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Thu, 8 Jul 2010 14:33:41 -0400 Subject: [PATCH] generalize inferred types for invariant positions --- collects/typed-scheme/infer/infer-unit.rkt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/collects/typed-scheme/infer/infer-unit.rkt b/collects/typed-scheme/infer/infer-unit.rkt index 33e2f23c7e..0877f8cf81 100644 --- a/collects/typed-scheme/infer/infer-unit.rkt +++ b/collects/typed-scheme/infer/infer-unit.rkt @@ -520,14 +520,19 @@ ;; variable: Symbol - variable to use instead, if v was a temp var for idx extension (define (constraint->type v h #:variable [variable #f]) (match v - [(struct c (S X T)) + [(c S X T) (let ([var (hash-ref h (or variable X) Constant)]) ;(printf "variance was: ~a~nR was ~a~nX was ~a~nS T ~a ~a~n" var R (or variable X) S T) (evcase var [Constant S] [Covariant S] [Contravariant T] - [Invariant S]))])) + [Invariant + (let ([gS (generalize S)]) + (printf "Inv var: ~a ~a ~a ~a\n" v S gS T) + (if (subtype gS T) + gS + S))]))])) ;; Since we don't add entries to the empty cset for index variables (since there is no ;; widest constraint, due to dcon-exacts), we must add substitutions here if no constraint ;; was found. If we're at this point and had no other constraints, then adding the