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 suggestions for inexhaustive case expression error #3561

Merged
merged 4 commits into from
Aug 27, 2024

Conversation

GearsDatapacks
Copy link
Contributor

Closes #3544.
Instead of just returning Failure when there are no rows, it runs exhaustiveness checking on the first subject of the case expression to give better suggestions to improve it.
In future we should maybe check other subjects too, to further improve this. Although this could produce a big decision tree, and we don't do that at the moment for other patterns so I left it.
For example, at the moment, for this code:

case True, False {}

It will suggest True, _ and False, _. (Actually it won't, because of #2426, but that's a separate issue)

However, if we check both subjects, it will suggest all four possible combinations.
However, consider this possibility:

type Wibble { A B C D }
case A, B, C, D {}

This would produce 4^4 = 256 possible options, which is a bit much. So I've left it with just the one for now.

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Oh this is lovely work, thank you very much! Left some small notes below

compiler-core/src/exhaustiveness.rs Outdated Show resolved Hide resolved
compiler-core/src/exhaustiveness.rs Show resolved Hide resolved
@GearsDatapacks
Copy link
Contributor Author

Alright, I've addressed all of the points you raised.

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you!!!

@lpil lpil merged commit d9b2d0d into gleam-lang:main Aug 27, 2024
12 checks passed
@GearsDatapacks GearsDatapacks deleted the fix-3544 branch August 27, 2024 10:45
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.

Improve suggestions for inexhaustive case expression error
3 participants