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

Improve type inference for record projection #2172

Merged
merged 2 commits into from
Oct 12, 2024
Merged

Improve type inference for record projection #2172

merged 2 commits into from
Oct 12, 2024

Conversation

byorgey
Copy link
Member

@byorgey byorgey commented Oct 12, 2024

When encountering a record projection r.x, we have to make sure that r has a record type. Previously, if the type of r was not manifestly a record type, we simply emitted an error message like "Can't infer the type of a record projection: r.x". This PR improves the situation in three related ways:

  • First, we now expand the type of r, if it turns out to be a type alias or recursive type. This was simply a bug: something like tydef R = [x:Int] end; def f : R -> Int = \r. r.x now works, as it should, but previously it was a type error.
  • Second, if the type of r is provably not a record type, we generate an appropriate type mismatch error rather than an unhelpful "Can't infer" error.
  • Finally, the "Can't infer" message itself is improved: it now says In the record projection r.x, can't infer whether the LHS has a record type. Try adding a type annotation..

@byorgey byorgey requested a review from xsebek October 12, 2024 16:58
Copy link
Member

@xsebek xsebek left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix! 👍

@byorgey byorgey added the merge me Trigger the merge process of the Pull request. label Oct 12, 2024
@mergify mergify bot merged commit 636be31 into main Oct 12, 2024
12 checks passed
@mergify mergify bot deleted the fix/infer-record branch October 12, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants