Skip to content

Commit f8700a5

Browse files
Cadence Embersamth
authored andcommitted
Fix type-checking list elements
This addresses a regression in commit 8d9cb49. That commit uses (when (andmap not errs) (expected-but-got ...)) to suppress some errors when type-checking list elements. Before this, there would be two errors reported: one for the list element itself and one for the surrounding list. However, as per #1379 this change suppressed too much. In certain cases it wouldn't report any errors for an invalid list. I couldn't figure out a way to report errors perfectly, so instead, I decided to revert the relevant change in 8d9cb49. This means list could report multiple errors again, but it's honestly not that bad. It shows the innermost location where the problem happened, as well as the wider context of the list, which can be helpful for locating and understanding the error. An example using the code from #1379: sample.rkt:13:41: Type Checker: type mismatch expected: (Listof Xexpr) given: (List Positive-Float-No-NaN) in: (list invalid) - snip - sample.rkt:9:2: Type Checker: type mismatch expected: Xexpr given: (List 'html (List 'body (List 'p String) (Pairof 'p Nothing))) in: (quasiquote (html (body (p (unquote (~a invalid))) (p (unquote-splicing ((inst map Xexpr Xexpr) values (list invalid))))))) - snip - Type Checker: Summary: 2 errors encountered location...: sample.rkt:13:41 sample.rkt:9:2 - snip - The performance fix from 8d9cb49 still works.
1 parent f0eba8f commit f8700a5

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,8 @@
130130
(add-typeof-expr #'op-name (ret (->* arg-tys return-ty :T+ #t)))
131131
(ret return-ty)))
132132
(or result
133-
;; When arguments to the list function fail to typecheck, the
134-
;; odds are those argument expressions are ill-typed. In that
135-
;; case, we should only report those type errors instead of the error
136-
;; that the result type of application of list doesn't match
137-
;; the expected one.
138-
(let-values ([(tys errs) (for/lists (tys errs)
139-
([i (in-list args-list)])
140-
(tc-expr/t* i))])
141-
(when (andmap not errs)
142-
(expected-but-got t (-Tuple tys)))
143-
(fix-results expected)))]
133+
(begin (expected-but-got t (-Tuple (map tc-expr/t args-list)))
134+
(fix-results expected)))]
144135
[else
145136
(define arg-tys (map tc-expr/t args-list))
146137
(define return-ty (-Tuple arg-tys))

0 commit comments

Comments
 (0)