typed-racket icon indicating copy to clipboard operation
typed-racket copied to clipboard

Fix type-checking list elements

Open cloudrac3r opened this issue 1 year ago • 1 comments

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.

cloudrac3r avatar Jun 27 '24 00:06 cloudrac3r

Thanks, this looks like a reasonable approach.

samth avatar Jun 27 '24 16:06 samth

@samth should we merge this?

sorawee avatar Jul 02 '24 19:07 sorawee