Skip to content

Comments

[Version 9.0] Feature support for pattern-matching enhancements#1460

Draft
BillWagner wants to merge 8 commits intodraft-v9from
v9-pattern-enhancements
Draft

[Version 9.0] Feature support for pattern-matching enhancements#1460
BillWagner wants to merge 8 commits intodraft-v9from
v9-pattern-enhancements

Conversation

@BillWagner
Copy link
Member

@BillWagner BillWagner commented Nov 10, 2025

@BillWagner BillWagner changed the base branch from draft-v8 to draft-v9 November 10, 2025 23:03
Add support for pattern additions

fix md and example

update headings

fix link warnings
@BillWagner BillWagner force-pushed the v9-pattern-enhancements branch from 4404f2a to d2c1cff Compare November 10, 2025 23:13
@RexJaeschke RexJaeschke added this to the C# 9.0 milestone Nov 11, 2025
@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: pending Proposal is available for review labels Nov 11, 2025
@RexJaeschke RexJaeschke changed the title [Version 9.0] V9 pattern enhancements [Version 9.0] Feature support for pattern-matching enhancements Nov 11, 2025
@BillWagner BillWagner self-assigned this Feb 17, 2026
Address the comments on specific lines in #1026.
Address the comments in the general review comment on #1026:

- I did continue to use the *logical_pattern* production. We use that term in the text, and it's a good shorthand so readers don't need to snake through the grammar of *disjunctive_pattern*, *conjunctive_pattern* and *negated_pattern*.

- I haven't addressed or created issues for the open questions in the proposal yet.
@BillWagner BillWagner closed this Feb 19, 2026
@BillWagner BillWagner reopened this Feb 19, 2026
@BillWagner
Copy link
Member Author

BillWagner commented Feb 19, 2026

The proposal has several open issues. We need to ensure this PR matches the final decision on those questions.

I've looked through the LDM notes, and here's my initial analysis:

Are and, or, and not some kind of contextual keyword?

Yes, and, or and not are contextual keywords in a pattern. Even if a type or identifier is in scope, it's a pattern keyword. when used as a pattern. However, you can write this (confusing though it is):

public class or { }

or or = new or();

if (or is or)
{ }

Semantic type for relational operators: We have proposed that when the input type is already a comparable primitive, that is the type of the comparison. However, when the input is not a comparable primitive, we treat the relational as including an implicit type test to the type of the constant on the right-hand-side of the relational. If the programmer intends to support more than one input type, that must be done explicitly:

That is the decision. Those rules are in this PR.

Most of the other open questions in the speclet have resolutions documented. I haven't yet verified that this PR includes those decisions. Now verified, or added in the 8th commit.

The only remaining issue is the diagnostic rules for relational and logical patterns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review: pending Proposal is available for review type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants