-
-
Notifications
You must be signed in to change notification settings - Fork 65
Document pattern matching limitations with compiler optimizations #263
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
Conversation
Co-authored-by: hazzik <[email protected]>
|
@copilot simplify the language. |
Co-authored-by: hazzik <[email protected]>
README.md
Outdated
|
|
||
| `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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot add SomeEnum definition for clarity.
Co-authored-by: hazzik <[email protected]>
README.md
Outdated
| x is TestEnum.Foo or TestEnum.Bar | ||
|
|
||
| // Might compile to: | ||
| (int)x <= 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot usually it is (uint)x <= 1u
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the example to use (uint)x cast as it's more accurate. Commit 75f3c10
Co-authored-by: hazzik <[email protected]>
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.