[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79051")]
public void Test2()
{
var source = """
class C
{
void M(ref byte b1)
{
_ = ref b1;
}
}
""";
CompileAndVerify(source, options: TestOptions.DebugDll).VerifyIL("C.M", """
{
// Code size 5 (0x5)
.maxstack 1
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldind.u1
IL_0003: pop
IL_0004: ret
}
""");
CompileAndVerify(source, options: TestOptions.ReleaseDll).VerifyIL("C.M", """
{
// Code size 4 (0x4)
.maxstack 1
IL_0000: ldarg.1
IL_0001: ldind.u1
IL_0002: pop
IL_0003: ret
}
""");
}
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79051")]
public void Test3()
{
var source = """
class C
{
void M()
{
ref byte b1 = ref GetRef();
_ = ref b1;
}
static ref byte GetRef() => throw null;
}
""";
CompileAndVerify(source, options: TestOptions.DebugDll).VerifyIL("C.M", """
{
// Code size 11 (0xb)
.maxstack 1
.locals init (byte& V_0) //b1
IL_0000: nop
IL_0001: call "ref byte C.GetRef()"
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldind.u1
IL_0009: pop
IL_000a: ret
}
""");
CompileAndVerify(source, options: TestOptions.ReleaseDll).VerifyIL("C.M", """
{
// Code size 8 (0x8)
.maxstack 1
IL_0000: call "ref byte C.GetRef()"
IL_0005: ldind.u1
IL_0006: pop
IL_0007: ret
}
""");
}