-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Closed
Copy link
Labels
Area-CompilersuntriagedIssues and PRs which have not yet been triaged by a leadIssues and PRs which have not yet been triaged by a lead
Description
Version Used:
Microsoft.CodeAnalysis.CSharp version 4.2.0
Steps to Reproduce:
Call NormalizeWhitespace() on code with nested fixed or using statements without a { } block between.
string code = @"
public unsafe void M1(string s1, string s2, string s3)
{
fixed (char* ptr1 = s1)
fixed (char* ptr2 = s2)
fixed (char* ptr3 = s3)
{
}
}
public void M2(string path)
{
using (FileStream fs = File.Create(path))
using (StreamWriter sw = new StreamWriter(fs))
{
}
}";
Console.WriteLine(ParseSyntaxTree(code).GetRoot().NormalizeWhitespace().ToFullString());Expected Behavior:
Output:
public unsafe void M1(string s1, string s2, string s3)
{
fixed (char* ptr1 = s1)
fixed (char* ptr2 = s2)
fixed (char* ptr3 = s3)
{
}
}
public void M2(string path)
{
using (FileStream fs = File.Create(path))
using (StreamWriter sw = new StreamWriter(fs))
{
}
}Actual Behavior:
Output:
public unsafe void M1(string s1, string s2, string s3)
{
fixed (char* ptr1 = s1)
fixed (char* ptr2 = s2)
fixed (char* ptr3 = s3)
{
}
}
public void M2(string path)
{
using (FileStream fs = File.Create(path))
using (StreamWriter sw = new StreamWriter(fs))
{
}
}Additional Notes:
With the usage of NormalizeWhitespace for source generators, this results in some awkwardly formatted generated code.
Auto-formatting code like this in Visual Studio stacks the statements without indentation like in the expected behaviour.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersuntriagedIssues and PRs which have not yet been triaged by a leadIssues and PRs which have not yet been triaged by a lead