diff --git a/tapl/mlish.rkt b/tapl/mlish.rkt index 59de9ba..1bc891e 100644 --- a/tapl/mlish.rkt +++ b/tapl/mlish.rkt @@ -924,7 +924,11 @@ #:with ([e- (ty)] ...) (⇑s (e ...) as Sequence) #:with [(acc- x- ...) body- ty_body] (infer/ctx+erase #'([acc : ty_init][x : ty] ...) #'body) - #:when (typecheck? #'ty_body #'ty_init) + #:fail-unless (typecheck? #'ty_body #'ty_init) + (type-error #:src stx + #:msg + "for/fold: Type of body and initial accumulator must be the same, given ~a and ~a" + #'ty_init #'ty_body) (⊢ (for/fold ([acc- init-]) ([x- e-] ...) body-) : ty_body)]) (define-typed-syntax for/hash diff --git a/tapl/tests/mlish-tests.rkt b/tapl/tests/mlish-tests.rkt index 790a885..5a23243 100644 --- a/tapl/tests/mlish-tests.rkt +++ b/tapl/tests/mlish-tests.rkt @@ -390,6 +390,9 @@ (check-type RT2 : (→/test {X Y} Y X (List X) (RecoTest X Y))) (check-type RT3 : (→/test X Y (RecoTest X Y))) +(typecheck-fail (for/fold ([x 1]) () "hello") + #:with-msg "for/fold: Type of body and initial accumulator must be the same, given Int and String") + ; ext-stlc tests -------------------------------------------------- ; tests for stlc extensions