-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersBugFeature - Interpolated String ImprovementsInterpolated string improvementsInterpolated string improvements
Milestone
Description
A regression that breaks an existing code that uses StringBuilder.
Version Used:
.NET 6.0 RC1 (Roslyn 4.0)
Steps to Reproduce:
Our codebase uses StringBuilder, but it is reproducible with any [InterpolatedStringHandler].
Use the following:
using System.Runtime.CompilerServices;
namespace Test;
class Program
{
static void Main()
{
Test test = new Test();
Foo("test", ref test);
}
static void Foo(string name, /* CAUSE! */ ref Test state)
{
state.Append($"{name}");
}
}
class Test
{
public void Append([InterpolatedStringHandlerArgument("")] ref MyInterpolatedStringHandler handler)
{
}
}
[InterpolatedStringHandler]
struct MyInterpolatedStringHandler
{
public MyInterpolatedStringHandler(int literalLength, int formattedCount, Test stringBuilder)
{
}
public void AppendFormatted<T>(T value)
{
Console.WriteLine("Hit");
}
}
Expected Behavior:
Should compile and execute the AppendFormatted method, which is the behavior when ref is removed from the state parameter.
Actual Behavior:
Compilation error:
error CS1615: Argument 3 may not be passed with the 'ref' keyword
(this means argument 3 of the MyInterpolatedStringHandler ctor, i.e. the instance of Test, )
The same happens if the method is invoked on a ref local.
addabis and prochan2
Metadata
Metadata
Assignees
Labels
Area-CompilersBugFeature - Interpolated String ImprovementsInterpolated string improvementsInterpolated string improvements