Skip to content

type matching, they talk about 4 cases but aren't the 2nd and the 3rd identical? #47076

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 2, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue description:

They say there are 4 cases for type pattern matching. But the second and the third seem to me to be identical:

  1. expr is an instance of a type that derives from type. In other words, the result of expr can be upcast to an instance of type.

  2. expr has a compile-time type that is a base class of type, and expr has a runtime type that is type or is derived from type. The compile-time type of a variable is the variable's type as defined in its declaration. The runtime type of a variable is the type of the instance that is assigned to that variable.

Am I missing something? If there is a very subtle difference, focus should be put on it because this way it's very difficult to spot it.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Fixes #22163.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/operators/patterns.md docs/csharp/language-reference/operators/patterns
docs/csharp/language-reference/operators/type-testing-and-cast.md docs/csharp/language-reference/operators/type-testing-and-cast

@BillWagner
Copy link
Member

Hi @copilot Can you start working on this again?

Copy link
Contributor Author

Copilot AI commented Jul 3, 2025

Hi @copilot Can you start working on this again?

I'll start working on this issue. Looking at the current documentation for type pattern matching, I can see the conditions that might be causing confusion. Let me analyze the current state and identify areas that need clarification.

…itions

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

Just a couple small changes, and then this is ready.

…mpatibility

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Jul 3, 2025
Copilot finished work on behalf of BillWagner July 3, 2025 15:05
@Copilot Copilot AI requested a review from BillWagner July 3, 2025 15:05
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review July 3, 2025 15:43
@BillWagner BillWagner requested a review from a team as a code owner July 3, 2025 15:43
@BillWagner BillWagner changed the title [WIP] type matching, they talk about 4 cases but aren't the 2nd and the 3rd identical? type matching, they talk about 4 cases but aren't the 2nd and the 3rd identical? Jul 3, 2025
@BillWagner BillWagner requested a review from IEvangelist July 3, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-csharp/svc lang-reference/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

type matching, they talk about 4 cases but aren't the 2nd and the 3rd identical?
2 participants