Given the following code:
namespace N
{
public class C
{
protected void Render()
{
if (true)
{
M(() =>
{
#nullable enable
if (true)
{
}
}
);
}
}
}
}
Formatting the document once results in:
namespace N
{
public class C
{
protected void Render()
{
if (true)
{
M(() =>
{
#nullable enable
if (true)
{
}
}
);
}
}
}
}
Note the position of the if (true). It has been moved by the formatter, but not by enough.
Foratting the document again results in:
namespace N
{
public class C
{
protected void Render()
{
if (true)
{
M(() =>
{
#nullable enable
if (true)
{
}
}
);
}
}
}
}
This is now properly formatted, and subsequent formatting does nothing, as you would expect.
Removing the #nullable enable from the file fixes the issue, and the formatter does the right thing on the first pass. Alternatively, changing the code so the lambda is assigned to a discard rather than passing it as an argument, also fixes the issue, even if the #nullable enable is left in place.
This bug is the cause of dotnet/razor#5676 in Razor, which generates code in a similar form to the example here.
Given the following code:
Formatting the document once results in:
Note the position of the
if (true). It has been moved by the formatter, but not by enough.Foratting the document again results in:
This is now properly formatted, and subsequent formatting does nothing, as you would expect.
Removing the
#nullable enablefrom the file fixes the issue, and the formatter does the right thing on the first pass. Alternatively, changing the code so the lambda is assigned to a discard rather than passing it as an argument, also fixes the issue, even if the#nullable enableis left in place.This bug is the cause of dotnet/razor#5676 in Razor, which generates code in a similar form to the example here.