Skip to content

Commit 1d43b58

Browse files
committed
Correctly extend tvars in the right place during inference.
Removes wrong extension of tvars in apply as well.
1 parent eaa41a2 commit 1d43b58

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/infer/infer-unit.rkt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,19 @@
272272
#:return-when (memq dbound* Y) #f
273273
(let* ([arg-mapping (cgen/list V X Y ts ss)]
274274
;; just add dbound as something that can be constrained
275-
[darg-mapping (% move-dotted-rest-to-dmap (cgen V (cons dbound X) Y t-dty s-dty) dbound dbound*)]
275+
[darg-mapping
276+
(extend-tvars (list dbound*)
277+
(% move-dotted-rest-to-dmap (cgen V (cons dbound X) Y t-dty s-dty) dbound dbound*))]
276278
[ret-mapping (cg s t)])
277279
(% cset-meet arg-mapping darg-mapping ret-mapping))]
278280
[((arr: ss s #f (cons s-dty dbound) '())
279281
(arr: ts t #f (cons t-dty (? (λ (db) (memq db Y)) dbound*)) '()))
280282
#:return-unless (= (length ss) (length ts)) #f
281283
(let* ([arg-mapping (cgen/list V X Y ts ss)]
282284
;; just add dbound as something that can be constrained
283-
[darg-mapping (% move-dotted-rest-to-dmap (cgen V (cons dbound* X) Y t-dty s-dty) dbound* dbound)]
285+
[darg-mapping
286+
(extend-tvars (list dbound)
287+
(% move-dotted-rest-to-dmap (cgen V (cons dbound* X) Y t-dty s-dty) dbound* dbound))]
284288
[ret-mapping (cg s t)])
285289
(% cset-meet arg-mapping darg-mapping ret-mapping))]
286290
;; * <: ...
@@ -438,13 +442,15 @@
438442
#:return-when (memq t-dbound Y) #f
439443
(% cset-meet
440444
(cgen/list V X Y ss ts)
441-
(% move-dotted-rest-to-dmap (cgen V (cons s-dbound X) Y s-dty t-dty) s-dbound t-dbound))]
445+
(extend-tvars (list t-dbound)
446+
(% move-dotted-rest-to-dmap (cgen V (cons s-dbound X) Y s-dty t-dty) s-dbound t-dbound)))]
442447
[((ValuesDots: ss s-dty s-dbound)
443448
(ValuesDots: ts t-dty (? (λ (db) (memq db Y)) t-dbound)))
444449
;; s-dbound can't be in Y, due to previous rule
445450
(% cset-meet
446451
(cgen/list V X Y ss ts)
447-
(% move-dotted-rest-to-dmap (cgen V (cons t-dbound X) Y s-dty t-dty) t-dbound s-dbound))]
452+
(extend-tvars (list s-dbound)
453+
(% move-dotted-rest-to-dmap (cgen V (cons t-dbound X) Y s-dty t-dty) t-dbound s-dbound)))]
448454

449455
;; they're subtypes. easy.
450456
[(a b)
@@ -585,10 +591,12 @@
585591
[((ListDots: s-dty (? (λ (db) (memq db Y)) s-dbound)) (ListDots: t-dty t-dbound))
586592
;; What should we do if both are in Y?
587593
#:return-when (memq t-dbound Y) #f
588-
(% move-dotted-rest-to-dmap (cgen V (cons s-dbound X) Y s-dty t-dty) s-dbound t-dbound)]
594+
(extend-tvars (list t-dbound)
595+
(% move-dotted-rest-to-dmap (cgen V (cons s-dbound X) Y s-dty t-dty) s-dbound t-dbound))]
589596
[((ListDots: s-dty s-dbound) (ListDots: t-dty (? (λ (db) (memq db Y)) t-dbound)))
590597
;; s-dbound can't be in Y, due to previous rule
591-
(% move-dotted-rest-to-dmap (cgen V (cons t-dbound X) Y s-dty t-dty) t-dbound s-dbound)]
598+
(extend-tvars (list s-dbound)
599+
(% move-dotted-rest-to-dmap (cgen V (cons t-dbound X) Y s-dty t-dty) t-dbound s-dbound))]
592600

593601
;; this constrains `dbound' to be |ts| - |ss|
594602
[((ListDots: s-dty dbound) (List: ts))

pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-apply.rkt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,10 @@
9898
;; ... function, ... arg
9999
[(and drest tail-bound
100100
(= (length domain) (length arg-tys))
101-
(if (eq? tail-bound (cdr drest))
102-
;; same bound on the ...s
103-
(infer fixed-vars (list dotted-var)
104-
(cons (make-ListDots tail-ty tail-bound) arg-tys)
105-
(cons (make-ListDots (car drest) (cdr drest)) domain)
106-
range)
107-
;; different bounds on the ...s
108-
(extend-tvars (list tail-bound (cdr drest))
109-
(extend-indexes (cdr drest)
110-
;; don't need to add tail-bound - it must already be an index
111-
(infer fixed-vars (list dotted-var)
112-
(cons (make-ListDots tail-ty tail-bound) arg-tys)
113-
(cons (make-ListDots (car drest) (cdr drest)) domain)
114-
range)))))
101+
(infer fixed-vars (list dotted-var)
102+
(cons (make-ListDots tail-ty tail-bound) arg-tys)
103+
(cons (make-ListDots (car drest) (cdr drest)) domain)
104+
range))
115105
=> finish]
116106
;; ... function, (Listof A) or (List A B C etc) arg
117107
[(and drest (not tail-bound)

0 commit comments

Comments
 (0)