Make inference on (list a ..) work better.
This commit is contained in:
parent
10cc76f22b
commit
e55f39dccd
|
@ -9,6 +9,7 @@
|
||||||
(types abbrev utils union substitute)
|
(types abbrev utils union substitute)
|
||||||
(rep type-rep)
|
(rep type-rep)
|
||||||
(env tvar-env)
|
(env tvar-env)
|
||||||
|
(prefix-in i: (infer infer))
|
||||||
|
|
||||||
(for-label
|
(for-label
|
||||||
racket/base
|
racket/base
|
||||||
|
@ -81,19 +82,20 @@
|
||||||
[_ (tc/app-regular #'form expected)])))
|
[_ (tc/app-regular #'form expected)])))
|
||||||
;; special case for `list'
|
;; special case for `list'
|
||||||
(pattern (list . args)
|
(pattern (list . args)
|
||||||
|
(let ()
|
||||||
|
(define vs (stx-map (λ (x) (gensym)) #'args))
|
||||||
|
(define l-type (-Tuple (map make-F vs)))
|
||||||
|
(define subst
|
||||||
(match expected
|
(match expected
|
||||||
[(tc-result1: (Listof: elem-ty))
|
[(tc-result1: t)
|
||||||
(for ([i (in-syntax #'args)])
|
;; We want to infer the largest vs that are still under the element types
|
||||||
(tc-expr/check i (ret elem-ty)))
|
(i:infer vs null (list l-type) (list t) (-values (list (-> l-type Univ))))]
|
||||||
(ret (-lst elem-ty))]
|
[_ #f]))
|
||||||
[(tc-result1: (List: (? (lambda (ts) (= (syntax-length #'args)
|
|
||||||
(length ts)))
|
|
||||||
ts)))
|
|
||||||
(ret (-Tuple
|
(ret (-Tuple
|
||||||
(for/list ([ac (in-syntax #'args)]
|
(for/list ([i (in-syntax #'args)] [v (in-list vs)])
|
||||||
[exp (in-list ts)])
|
(if subst
|
||||||
(tc-expr/check/t ac (ret exp)))))]
|
(tc-expr/check/t i (ret (subst-all subst (make-F v))))
|
||||||
[_ (ret (-Tuple (stx-map tc-expr/t #'args)))]))
|
(tc-expr/t i)))))))
|
||||||
;; special case for `list*'
|
;; special case for `list*'
|
||||||
(pattern (list* . args)
|
(pattern (list* . args)
|
||||||
(match-let* ([(list tys ... last) (stx-map tc-expr/t #'args)])
|
(match-let* ([(list tys ... last) (stx-map tc-expr/t #'args)])
|
||||||
|
|
|
@ -2991,6 +2991,12 @@
|
||||||
((letrec ([lp (lambda (x) lp)]) lp) 'y)
|
((letrec ([lp (lambda (x) lp)]) lp) 'y)
|
||||||
#:ret (ret (t:-> -Symbol Univ))
|
#:ret (ret (t:-> -Symbol Univ))
|
||||||
#:expected (ret (t:-> -Symbol Univ) -no-filter -no-obj)]
|
#:expected (ret (t:-> -Symbol Univ) -no-filter -no-obj)]
|
||||||
|
|
||||||
|
[tc-e
|
||||||
|
(list (vector 1 2 3))
|
||||||
|
#:ret (ret (-seq (-vec Univ)))
|
||||||
|
#:expected (ret (-seq (-vec Univ)))]
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
(test-suite
|
(test-suite
|
||||||
|
|
Loading…
Reference in New Issue
Block a user