From 579815512eb2b49d4a1311bf5e4d3a1126624d5e Mon Sep 17 00:00:00 2001 From: Stephen Chang Date: Wed, 20 Apr 2016 19:18:33 -0400 Subject: [PATCH] for/fold produces better err msg --- tapl/mlish.rkt | 6 +++++- tapl/tests/mlish-tests.rkt | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) 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