diff --git a/collects/tests/typed-scheme/succeed/for-in-range.rkt b/collects/tests/typed-scheme/succeed/for-in-range.rkt new file mode 100644 index 00000000..213e14dd --- /dev/null +++ b/collects/tests/typed-scheme/succeed/for-in-range.rkt @@ -0,0 +1,3 @@ +#lang typed/racket + +(for: ([i : Integer (in-range 10 0 -1)]) i) \ No newline at end of file diff --git a/collects/typed-scheme/typecheck/find-annotation.rkt b/collects/typed-scheme/typecheck/find-annotation.rkt index ceb9b79a..48b5612f 100644 --- a/collects/typed-scheme/typecheck/find-annotation.rkt +++ b/collects/typed-scheme/typecheck/find-annotation.rkt @@ -45,13 +45,19 @@ ;; expr id -> type or #f ;; if there is a binding in stx of the form: -;; (let ([x (reverse name)]) e) +;; (let ([x (reverse name)]) e) or +;; (let ([x name]) e) ;; where x has a type annotation, return that annotation, otherwise #f (define (find-annotation stx name) (define (find s) (find-annotation s name)) (define (match? b) (syntax-parse b #:literals (#%plain-app reverse) + [c:lv-clause + #:with n:id #'c.e + #:with (v) #'(c.v ...) + #:fail-unless (free-identifier=? name #'n) #f + (or (type-annotation #'v) (lookup-type/lexical #'v #:fail (lambda _ #f)))] [c:lv-clause #:with (#%plain-app reverse n:id) #'c.e #:with (v) #'(c.v ...) diff --git a/collects/typed-scheme/typecheck/tc-app.rkt b/collects/typed-scheme/typecheck/tc-app.rkt index aef7db1e..d68d056c 100644 --- a/collects/typed-scheme/typecheck/tc-app.rkt +++ b/collects/typed-scheme/typecheck/tc-app.rkt @@ -235,12 +235,14 @@ (tc/rec-lambda/check form args body lp (cons acc-ty ts) expected) expected)] ;; special case when argument needs inference - [_ + [(_ (body*) _) (let ([ts (for/list ([ac (syntax->list actuals)] [f (syntax->list args)]) - (let ([infer-t (type-annotation f #:infer #t)]) + (let* ([infer-t (or (type-annotation f #:infer #t) + (find-annotation #'body* f))]) (if infer-t - (check-below (tc-expr/t ac) infer-t) + (begin (check-below (tc-expr/t ac) infer-t) + infer-t) (generalize (tc-expr/t ac)))))]) (tc/rec-lambda/check form args body lp ts expected) expected)]))