-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Milestone
Description
Description
The assumption here is incorrect:
runtime/src/libraries/System.Text.RegularExpressions/gen/UpgradeToRegexGeneratorCodeFixer.cs
Lines 287 to 289 in d434c4a
| // The options were formatted as an int, which means the runtime couldn't | |
| // produce a textual representation. So just output casting the value as an int. | |
| Debug.Fail("This shouldn't happen, as we should only get to the point of emitting code if RegexOptions was valid."); |
This path is reachable.
Reproduction Steps
Tests extracted from #71264:
[Fact]
public async Task InvalidRegexOptions()
{
string test = @"using System.Text.RegularExpressions;
public class A
{
public partial class B
{
public class C
{
public partial class D
{
public void Foo()
{
Regex regex = [|new Regex(""pattern"", (RegexOptions)0x0800)|];
}
}
}
}
}
";
string fixedSource = @"using System.Text.RegularExpressions;
public partial class A
{
public partial class B
{
public partial class C
{
public partial class D
{
public void Foo()
{
Regex regex = MyRegex();
}
[RegexGenerator(""pattern"", (RegexOptions)2048)]
private static partial Regex MyRegex();
}
}
}
}
";
await VerifyCS.VerifyCodeFixAsync(test, fixedSource);
}
[Fact]
public async Task InvalidRegexOptions_Negative()
{
string test = @"using System.Text.RegularExpressions;
public class A
{
public partial class B
{
public class C
{
public partial class D
{
public void Foo()
{
Regex regex = [|new Regex(""pattern"", (RegexOptions)(-10000))|];
}
}
}
}
}
";
string fixedSource = @"using System.Text.RegularExpressions;
public partial class A
{
public partial class B
{
public partial class C
{
public partial class D
{
public void Foo()
{
Regex regex = MyRegex();
}
[RegexGenerator(""pattern"", (RegexOptions)(-10000))]
private static partial Regex MyRegex();
}
}
}
}
";
await new VerifyCS.Test(null, usePreviewLanguageVersion: true, 1)
{
TestCode = test,
FixedCode = fixedSource,
CodeActionValidationMode = CodeActionValidationMode.None,
}.RunAsync();
}Expected behavior
Tests above should pass.
Actual behavior
Debug.Fail is hit.
Reactions are currently unavailable