close
Skip to content

fix(compiler): Handle non-exhaustive record patterns#2274

Merged
ospencer merged 3 commits into
grain-lang:mainfrom
spotandjake:spotandjake-rec-exhaustive
Apr 22, 2025
Merged

fix(compiler): Handle non-exhaustive record patterns#2274
ospencer merged 3 commits into
grain-lang:mainfrom
spotandjake:spotandjake-rec-exhaustive

Conversation

@spotandjake
Copy link
Copy Markdown
Member

@spotandjake spotandjake commented Apr 15, 2025

This implements exhaustiveness checking both for regular records and inline records. I split the two into seperate commits as we need the record pattern logic for inline adt's but some additional debugging was needed to get inlines working.

Record Exhaustiveness

I mostly ported the logic over from parmatch.ml in the ocaml compiler, though they are not 1 for 1 as our implementation has diverged a decent bit, the foundational logic is the same.

Inline ADT Records

It was a little weird that previously including a record variant would cause you to get no exhaustiveness info even on non record variants in your enum, it turned out this was because when converting back to our parsetree nodes we were just treating everything as a tuple causing a misused_inline_record error internally.

Changes to queue.gr, mixedPatternMatching.gr

This actually revealed some cases we missed, so I implemented them, the case in queue.gr would never actually be possible because of how we build the queues.

Closes: #2221, #2219

Comment thread compiler/src/typed/parmatch.re Outdated
Copy link
Copy Markdown
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

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

Looks good; thanks for getting this implemented.

@ospencer ospencer changed the title feat(grainc): Handle exhaustive checking on records fix(compiler): Handle non-exhaustive record patterns Apr 22, 2025
@ospencer ospencer enabled auto-merge April 22, 2025 16:29
@ospencer ospencer added this pull request to the merge queue Apr 22, 2025
Merged via the queue into grain-lang:main with commit 0431e74 Apr 22, 2025
12 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pattern matching exhaustiveness for records

2 participants