Fix bug with use of match with ... and annotation.

svn: r16216
This commit is contained in:
Sam Tobin-Hochstadt 2009-10-02 16:20:30 +00:00
parent a25ddaae54
commit 6efd0abc13
4 changed files with 22 additions and 8 deletions

View File

@ -0,0 +1,9 @@
#lang typed-scheme
(require scheme/match)
(: post-eval : -> Number)
;; evaluates a postfix sequence of items, using a stack
(define (post-eval)
(match '(1 2)
[(list (? number? #{stack : (Listof Number)}) ...) 3]))

View File

@ -1,9 +1,10 @@
#lang scheme/base #lang scheme/base
(require "../utils/utils.ss" syntax/parse (require "../utils/utils.ss" syntax/parse
scheme/contract scheme/contract scheme/trace
(rep type-rep) (rep type-rep)
(private type-annotation)) (private type-annotation)
(for-template scheme/base))
(p/c [find-annotation (syntax? identifier? . -> . (or/c #f Type/c))]) (p/c [find-annotation (syntax? identifier? . -> . (or/c #f Type/c))])
@ -63,3 +64,5 @@
(find #'body))] (find #'body))]
[e:core-expr [e:core-expr
(ormap find (syntax->list #'(e.expr ...)))])) (ormap find (syntax->list #'(e.expr ...)))]))
;(trace find-annotation)

View File

@ -143,17 +143,18 @@
(define (let-loop-check form lp actuals args body expected) (define (let-loop-check form lp actuals args body expected)
(syntax-parse #`(#,args #,body #,actuals) (syntax-parse #`(#,args #,body #,actuals)
#:literals (#%plain-app if null?) #:literals (#%plain-app if null? pair?)
[((val acc ...) [((val acc ...)
((if (#%plain-app null? val*) thn els)) ((~and inner-body (if (#%plain-app (~or pair? null?) val*) thn els)))
(actual actuals ...)) (actual actuals ...))
#:fail-unless
(and (free-identifier=? #'val #'val*) (and (free-identifier=? #'val #'val*)
(ormap (lambda (a) (find-annotation #'(if (#%plain-app null? val*) thn els) a)) (ormap (lambda (a) (find-annotation #'inner-body a))
(syntax->list #'(acc ...)))) (syntax->list #'(acc ...)))) #f
(let* ([ts1 (generalize (tc-expr/t #'actual))] (let* ([ts1 (generalize (tc-expr/t #'actual))]
[ann-ts (for/list ([a (in-syntax #'(acc ...))] [ann-ts (for/list ([a (in-syntax #'(acc ...))]
[ac (in-syntax #'(actuals ...))]) [ac (in-syntax #'(actuals ...))])
(or (find-annotation #'(if (#%plain-app null? val*) thn els) a) (or (find-annotation #'inner-body a)
(generalize (tc-expr/t ac))))] (generalize (tc-expr/t ac))))]
[ts (cons ts1 ann-ts)]) [ts (cons ts1 ann-ts)])
;; check that the actual arguments are ok here ;; check that the actual arguments are ok here
@ -164,7 +165,7 @@
(tc/rec-lambda/check form args body lp ts expected) (tc/rec-lambda/check form args body lp ts expected)
expected)] expected)]
;; special case when argument needs inference ;; special case when argument needs inference
[_ [_
(let ([ts (for/list ([ac (syntax->list actuals)] (let ([ts (for/list ([ac (syntax->list actuals)]
[f (syntax->list args)]) [f (syntax->list args)])
(or (or

View File

@ -31,6 +31,7 @@
(match t* (match t*
[(Value: '()) (-lst Univ)] [(Value: '()) (-lst Univ)]
[(Mu: var (Union: (list (Value: '()) (Pair: _ (F: var))))) t*] [(Mu: var (Union: (list (Value: '()) (Pair: _ (F: var))))) t*]
[(Pair: t1 (Value: '())) (-lst t1)]
[(Pair: t1 t2) [(Pair: t1 t2)
(let ([t-new (loop t2)]) (let ([t-new (loop t2)])
(if (type-equal? (-lst t1) t-new) (if (type-equal? (-lst t1) t-new)