Document pattern matching limitations with compiler optimizations - #263
Merged
Conversation
Co-authored-by: hazzik <144791+hazzik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] 'or' pattern matching issue
Document pattern matching limitations with compiler optimizations
Oct 2, 2025
Owner
|
@copilot simplify the language. |
Co-authored-by: hazzik <144791+hazzik@users.noreply.github.com>
Contributor
Author
hazzik
reviewed
Oct 2, 2025
|
|
||
| `is ... or ...` pattern matching cannot always be decompiled due to compiler optimizations. The compiler may optimize enum patterns to use comparison operators, making it impossible to distinguish between genuine comparisons and optimized patterns. | ||
|
|
||
| For example, `x is SomeEnum.Value1 or SomeEnum.Value2` might compile to `(int)x <= 1`. |
Co-authored-by: hazzik <144791+hazzik@users.noreply.github.com>
hazzik
reviewed
Oct 2, 2025
hazzik
reviewed
Oct 2, 2025
Co-authored-by: hazzik <144791+hazzik@users.noreply.github.com>
hazzik
marked this pull request as ready for review
October 2, 2025 04:53
hazzik
enabled auto-merge (squash)
October 2, 2025 04:53
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.
Fixes #237 by documenting the limitation that DelegateDecompiler cannot always decompile
is ... or ...pattern matching due to compiler optimizations.The Problem
When using pattern matching with the
is ... or ...syntax, the C# compiler sometimes optimizes these patterns into comparison operations for performance. For example:This optimization makes it impossible for DelegateDecompiler to distinguish between:
As noted in the issue discussion, there's no way to determine how the comparison operator came about - whether it was from optimized
is … or …pattern matching or from explicit user code.The Solution
This PR adds clear documentation in the README.md Limitations section explaining this constraint. The documentation:
This addresses the issue by setting proper expectations for users encountering this limitation.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.