-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix regex fixer to maintain string literal syntax #78172
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue DetailsFixes #78113
|
src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs
Outdated
Show resolved
Hide resolved
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.
LGTM
Unless I'm missing something, this will generate code that won't compile sometimes. For example, the case of: using System.Text.RegularExpressions;
partial class Program
{
static void Main(string[] args)
{
const string pattern = @"a|b\s\n";
const string pattern2 = $"{pattern}2";
Regex regex = new Regex(pattern2);
}
} If I'm following correctly, this will generate the new static method and pass in pattern2 as the argument to the GeneratedRegex attribute, which is not in scope so code won't compile. This is why today we instead have to evaluate the constant value and then use that as the argument to the attribute. If I'm correct with my assumption here, I'm not sure why we don't have a test that checks that, but we should add one if we don't. |
We don't :) |
src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs
Outdated
Show resolved
Hide resolved
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.
Thanks for fixing this @stephentoub and thanks for the help @Youssef1313!
Fixes #78113