Skip to content

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
@aryairani aryairani deleted the travis/empty-pattern-match branch July 30, 2024 02:31
@ChrisPenner
Copy link
Member

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