Skip to content

Commit e52fa97

Browse files
committed
improves error reporting for (list ....)
closes #995
1 parent 5b502e7 commit e52fa97

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

typed-racket-lib/typed-racket/typecheck/signatures.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
[cond-contracted tc-expr/check/t? (syntax? (or/c tc-results/c #f) . -> . (or/c Type? #f))]
1414
[cond-contracted tc-body/check (syntax? (or/c tc-results/c #f) . -> . full-tc-results/c)]
1515
[cond-contracted tc-expr/t (syntax? . -> . Type?)]
16+
[cond-contracted tc-expr/t* (syntax? . -> . (values Type? boolean?))]
1617
[cond-contracted single-value ((syntax?) ((or/c tc-results/c #f)) . ->* . full-tc-results/c)]
1718
[cond-contracted tc-dep-fun-arg ((syntax?) ((or/c tc-results/c #f)) . ->* . full-tc-results/c)]))
1819

typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-list.rkt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(require "../../utils/utils.rkt"
55
"signatures.rkt"
66
"utils.rkt"
7-
syntax/parse syntax/stx racket/match racket/sequence
7+
syntax/parse syntax/stx racket/match
88
(typecheck signatures tc-funapp error-message)
99
(types abbrev type-table utils substitute)
1010
(rep type-rep)
@@ -101,6 +101,7 @@
101101
;; We want to infer the largest vs that are still under the element types
102102
(define substs (i:infer vs null (list l-type) (list t) (-values (list (-> l-type Univ)))
103103
#:multiple? #t))
104+
104105
(cond
105106
[substs
106107
(define result
@@ -113,8 +114,12 @@
113114
(add-typeof-expr #'op-name (ret (->* arg-tys return-ty)))
114115
(ret return-ty)))
115116
(or result
116-
(begin (expected-but-got t (-Tuple (map tc-expr/t args-list)))
117-
(fix-results expected)))]
117+
(let-values ([(tys errs) (for/lists (tys errs)
118+
([i (in-list args-list)])
119+
(tc-expr/t* i))])
120+
(when (andmap not errs)
121+
(expected-but-got t (-Tuple tys)))
122+
(fix-results expected)))]
118123
[else
119124
(define arg-tys (map tc-expr/t args-list))
120125
(define return-ty (-Tuple arg-tys))

typed-racket-lib/typed-racket/typecheck/tc-expr-unit.rkt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
[(tc-result1: t _ _) t]
6868
[t (int-err "tc-expr returned ~a, not a single tc-result, for ~a" t (syntax->datum e))]))
6969

70+
(define (tc-expr/t* expr)
71+
(parameterize ([current-type-error? #f])
72+
(values (tc-expr/t expr) (current-type-error?))))
73+
7074
(define (tc-expr/check/t e t)
7175
(match (tc-expr/check e t)
7276
[(tc-result1: t) t]))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#;
2+
(exn-pred #rx".*expected: Symbol.*given: String")
3+
#lang typed/racket
4+
5+
(ann (list (symbol->string "10"))
6+
(Listof String))

typed-racket-test/unit-tests/typecheck-tests.rkt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,6 +3488,12 @@
34883488
(list (vector 1 2 3))
34893489
#:ret (tc-ret (-seq (-vec Univ)))
34903490
#:expected (tc-ret (-seq (-vec Univ)))]
3491+
3492+
[tc-err
3493+
(ann (list (symbol->string "10")) (Listof String))
3494+
#:ret (tc-ret (-lst -String))
3495+
#:expected (tc-ret (-lst -String))
3496+
#:msg #rx"expected: Symbol.*given: String.*"]
34913497

34923498
;; PR 14557 - apply union of functions with different return values
34933499
[tc-err

0 commit comments

Comments
 (0)