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

[bugfix] permit empty matches #5256

Merged
merged 2 commits into from
Jul 30, 2024
Merged

[bugfix] permit empty matches #5256

merged 2 commits into from
Jul 30, 2024

Conversation

tstat
Copy link
Member

@tstat tstat commented Jul 30, 2024

Overview

Fix a bug in the pattern match coverage checker's desugarer that interpreted an empty match as a wildcard match.

Simple test

Here is a simple transcript test when this diff is applied to #5249:

inhabited types are rejected

unique type T = A | B

bonk : T -> ()
bonk x = match x with

  Loading changes detected in scratch.u.

  Pattern match doesn't cover all possible cases:
        4 | bonk x = match x with
    
  
  Patterns not matched:
  
    * A
    * B

uninhabited types are accepted

unique type V =

bonk : V -> ()
bonk x = match x with

  Loading changes detected in scratch.u.

  I found and typechecked these definitions in scratch.u. If you
  do an `add` or `update`, here's how your codebase would
  change:
  
    ⍟ These new definitions are ok to `add`:
    
      type V
      bonk : V -> ()

Test coverage

Just running the above transcript

@tstat tstat requested a review from aryairani July 30, 2024 00:59
m (GrdTree (PmGrd vt v loc) loc)
desugarMatch loc0 scrutineeType v0 cs0 =
traverse desugarClause cs0 >>= \case
[] -> pure $ Leaf loc0
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the bug, an empty set of match cases is not a Leaf, it is an empty tree.

@aryairani
Copy link
Contributor

🙏 🏆 Thank you!

@aryairani
Copy link
Contributor

Here is a simple transcript test when this diff is applied to #5249:

cc @ChrisPenner

@aryairani aryairani merged commit 4acebf0 into trunk Jul 30, 2024
35 checks passed
@aryairani aryairani deleted the travis/empty-pattern-match branch July 30, 2024 02:31
@ChrisPenner
Copy link
Contributor

Thanks @tstat ! Much appreciated

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