Match element diagnostics improvements - #12680
Open
nichturner wants to merge 7 commits into
Open
Conversation
Updated parser tree grammar to recognize an empty element for a wildcard case as valid syntax, which previously it did not.
Updated compiler to leave an error message when a match element has no cases. Updated basic syntax test to verify proper behavior.
nichturner
force-pushed
the
feature/initial-match-diagnostics-improvements
branch
from
July 28, 2026 16:41
ea5ec43 to
8dc6914
Compare
0x6e
reviewed
Jul 29, 2026
ogoffart
reviewed
Jul 31, 2026
ogoffart
left a comment
Member
There was a problem hiding this comment.
Please update the match-elements.mdx to reflect the changes.
Found and updated all references of "match statement/expression" to "match element", using consistent terminology accross messages. Updated syntax tests to output proper error messages with consistent messages.
Created MatchElementInfo struct to handle and track match element resolution, initially to target duplicated error messages with a wildcard case. Created and ran new test verifying proper error messages while using non-literal cases with a wildcard present
Created new MatchCaseInfo struct to keep track of the syntax nodes of a match element to ensure that repeated cases produce a compiler error. Created new match element syntax test to verify proper compiler errors when using a duplicate case in a match element. Tests verify functionality on a variety of types and type coercion.
Created check_exhaustiveness helper function to detect whether a case is exhaustively represented in a match element. Enums and booleans may be covered entirely without a wildcard case, and any other type must have a wildcard case. Created new test to verify error outputs with non-exhaustive match element cases for various data tyes and updated previous match element syntax tests to be fully exhaustive.
…ildcard case Updated parser to no longer produce a compiler error if there is only a wildcard case within a match element. Updated object tree to anticipate this case and unconditionally render the element. Reran syntax tests to remove previous error messages and added a new driver test to verify functionality.
nichturner
force-pushed
the
feature/initial-match-diagnostics-improvements
branch
from
August 3, 2026 17:40
8dc6914 to
df6c134
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the
Diagnosticssection of #1307 after an experimental implementation ofmatchelements was merged in #12021.Standardized Terminology
Updated all references to
match expressionormatch statementto bematch element.Zero Cases
A match element with zero cases will now produce a compiler error.
Duplicate Cases
A match element with two cases that resolve to the same value will now produce a compiler error.
Exhaustiveness
A type that can be covered completely (bool, enum) must do so, otherwise a
*case is required. All other types require the*case.Unconditional Wildcard Cases
Added support for an empty match element with only a wildcard case to unconditionally render the wildcard case element.
Single Error Outputs
Fixed issue with the same error message being reported multiple times when a
*case is present.