From b2010f384248bf16c8eea3068468756efe003ad6 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Fri, 27 Jun 2014 00:01:49 -0400 Subject: [PATCH] Fix for/fold typechecking on null accumulator Closes PR 13259 original commit: 0b3b1f5d9469da8990517dc11d7e63a7302d7966 --- .../typed-racket/typecheck/tc-app/tc-app-lambda.rkt | 5 ++++- .../tests/typed-racket/unit-tests/typecheck-tests.rkt | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt index 1de3f42e..4a0c2a86 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt @@ -85,7 +85,7 @@ ;; special case `for/list' [((val acc ...) ((~and inner-body (if e1 e2 e3:id))) - (null actuals ...)) + (~and (null actuals ...) (null-exp . _))) #:when (free-identifier=? #'val #'e3) (let ([ts (for/list ([ac (in-syntax #'(actuals ...))] [f (in-syntax #'(acc ...))]) @@ -99,6 +99,9 @@ [(tc-result1: (and t (Listof: _))) t] [_ #f]) (generalize -Null))]) + ;; this check is needed because the type annotation may come + ;; from `for/fold` and it won't necessarily be a list type + (tc-expr/check #'null-exp (ret acc-ty)) (define-values (fun-results body-results) (tc/rec-lambda/check args body lp (cons acc-ty ts) expected)) (add-typeof-expr lam fun-results) diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt index d7eb57de..991e9a49 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt @@ -3113,6 +3113,15 @@ (define f (lambda () 'hi)) (f)) #:msg "cannot apply function of type Procedure"] + + ;; PR 13259 + [tc-err + (let () + (: y String) + (define y (for/fold: ((x : String null)) ((v : String null)) x)) + y) + #:ret (ret -String) + #:msg "expected: String.*given: Null"] ) (test-suite