-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
area-System.Text.RegularExpressionsbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description
If A.cs and B.cs both have public partial class C and both have methods needing a new Regex() -> [GeneratedRegex] replacement, the source generator fix puts MyRegex() in both files, which causes a compilation error. I invoked the fix by running dotnet-format project.csproj --diagnostics SYSLIB1045 --no-restore.
Reproduction Steps
using System.Text.RegularExpressions;
namespace RegexReplacement
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
internal partial class C
{
public static Regex A()
{
var r = new Regex("abc");
return r;
}
}
internal partial class C
{
public static Regex B()
{
var r = new Regex("def");
return r;
}
}
}
Expected behavior
using System.Text.RegularExpressions;
namespace RegexReplacement
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
internal partial class C
{
public static Regex A()
{
var r = MyRegex();
return r;
}
[GeneratedRegex("abc")]
private static partial Regex MyRegex();
}
internal partial class C
{
public static Regex B()
{
var r = MyRegex();
return r;
}
[GeneratedRegex("def")]
private static partial Regex MyRegex2();
}
}
Actual behavior
using System.Text.RegularExpressions;
namespace RegexReplacement
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
internal partial class C
{
public static Regex A()
{
var r = MyRegex();
return r;
}
[GeneratedRegex("abc")]
private static partial Regex MyRegex();
}
internal partial class C
{
public static Regex B()
{
var r = MyRegex();
return r;
}
[GeneratedRegex("def")]
private static partial Regex MyRegex();
}
}
Regression?
no
Known Workarounds
manual fix
Configuration
$ dotnet-format --version
7.0.351204+c1136d16ab588f45727fe908212b90578edc2aff
7.0.100-rc.1.22431.12 [C:\Program Files\dotnet\sdk]
Other information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-System.Text.RegularExpressionsbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged