Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type-checking list elements #1382

Merged
merged 1 commit into from
Jul 2, 2024
Merged

Fix type-checking list elements #1382

merged 1 commit into from
Jul 2, 2024

Conversation

cloudrac3r
Copy link

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.

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 racket#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 racket#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.
@samth
Copy link
Member

samth commented Jun 27, 2024

Thanks, this looks like a reasonable approach.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 0 files in this pull request and found no issues.

@sorawee
Copy link
Contributor

sorawee commented Jul 2, 2024

@samth should we merge this?

@samth samth merged commit f8700a5 into racket:master Jul 2, 2024
5 checks passed
@cloudrac3r cloudrac3r deleted the fix-list branch July 2, 2024 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants