-
Notifications
You must be signed in to change notification settings - Fork 5.1k
"Convert to GeneratedRegexAttribute" mangles Constants #116149
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
@copilot, please try again |
timed out. let's try again while we figure out how to raise the timeout. |
I've implemented a fix for the issue with the "Convert to GeneratedRegexAttribute" code fixer mangling constant RegexOptions. The problem was in the The fix reorders the checks in the Changes can be seen in commit fb428af. |
@copilot this looks close, but DiagnosticEmittedForConstantOptions is failing. Please make sure all RegularExpressions tests pass. Do not comment any tests out. Update baselines in tests if needed and appropriate. |
The newly added test file also isn't included in the csproj and thus isn't actually executing. We should update the copilot instructions file to cite that we strongly prefer new tests be added to existing files rather than new ones, but when they're added to new ones, the csproj should be updated, assuming it's manually including all relevant files. |
Fixed the issue in commit d5b0c8e. The |
Fixed in commit c34e0f2. Moved the test cases from the new test file into the existing |
@copilot make sure that all new code paths are tested by tests in UpgradeToGeneratedRegexAnalyzerTests.cs. You only have one test which is insufficient on its own. |
Added comprehensive test coverage for all new code paths in commit 970bc3e. The fix now includes tests for:
All tests now pass and cover the different branches in the |
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions |
As far as I can tell this is reasonable and ready for review. |
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.
Pull Request Overview
This PR addresses the issue of constant RegexOptions being mangled by the "Convert to GeneratedRegexAttribute" fixer by updating both the test cases and the code fixer logic. Key changes include:
- Modifying test cases in UpgradeToGeneratedRegexAnalyzerTests.cs to correctly handle both local and field constant patterns and options.
- Updating UpgradeToGeneratedRegexCodeFixer.cs to preserve constant field references for RegexOptions while expanding local constants.
- Adjusting test data scenarios to include mixed and static field options to verify the fix.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/UpgradeToGeneratedRegexAnalyzerTests.cs | Updated tests to use non-empty constant patterns and preserve constant field references for RegexOptions. |
src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs | Revised code fixer logic to distinguish between local constant expansion and constant field preservation. |
.github/copilot-instructions.md | Updated test and build guidelines to improve test file management and execution. |
Comments suppressed due to low confidence (1)
src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs:316
- Ensure that converting RegexOptions via ToString() yields a valid and correctly formatted constant expression for the GeneratedRegex attribute. Consider using a helper function to generate a fully qualified enum expression if needed.
string optionsLiteral = Literal(((RegexOptions)(int)argument.Value.ConstantValue.Value!).ToString());
src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs
Outdated
Show resolved
Hide resolved
9799eea
to
5ec8022
Compare
UpgradeToGeneratedRegexCodeFixer.cs
to preserve constant RegexOptions referencesFixes #109784.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.