Skip to content

Commit 722f011

Browse files
authored
Merge pull request #19440 from VSadov/fix19434
Regression test for #19434 which appear to be fixed.
2 parents 3506fca + 2458ada commit 722f011

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22872,5 +22872,78 @@ void M<T>()
2287222872
Diagnostic(ErrorCode.ERR_TypelessTupleInAs, "(0, null) as (int, T)?").WithLocation(6, 17)
2287322873
);
2287422874
}
22875+
22876+
[Fact]
22877+
[WorkItem(19434, "https://github.com/dotnet/roslyn/issues/19434")]
22878+
public void ExplicitTupleLiteralConversionWithNullable01()
22879+
{
22880+
var source = @"
22881+
class C
22882+
{
22883+
static void Main()
22884+
{
22885+
int x = 1;
22886+
var y = ((byte, byte)?)(x, x);
22887+
System.Console.WriteLine(y.Value);
22888+
}
22889+
}
22890+
";
22891+
22892+
var comp = CompileAndVerify(source,
22893+
additionalRefs: s_valueTupleRefs, options: TestOptions.DebugExe, expectedOutput:
22894+
@"(1, 1)");
22895+
22896+
comp.VerifyIL("C.Main()", @"
22897+
{
22898+
// Code size 38 (0x26)
22899+
.maxstack 3
22900+
.locals init (int V_0, //x
22901+
(byte, byte)? V_1) //y
22902+
IL_0000: nop
22903+
IL_0001: ldc.i4.1
22904+
IL_0002: stloc.0
22905+
IL_0003: ldloca.s V_1
22906+
IL_0005: ldloc.0
22907+
IL_0006: conv.u1
22908+
IL_0007: ldloc.0
22909+
IL_0008: conv.u1
22910+
IL_0009: newobj ""System.ValueTuple<byte, byte>..ctor(byte, byte)""
22911+
IL_000e: call ""(byte, byte)?..ctor((byte, byte))""
22912+
IL_0013: ldloca.s V_1
22913+
IL_0015: call ""(byte, byte) (byte, byte)?.Value.get""
22914+
IL_001a: box ""System.ValueTuple<byte, byte>""
22915+
IL_001f: call ""void System.Console.WriteLine(object)""
22916+
IL_0024: nop
22917+
IL_0025: ret
22918+
}
22919+
");
22920+
22921+
comp = CompileAndVerify(source,
22922+
additionalRefs: s_valueTupleRefs, options: TestOptions.ReleaseExe, expectedOutput:
22923+
@"(1, 1)");
22924+
22925+
comp.VerifyIL("C.Main()", @"
22926+
{
22927+
// Code size 36 (0x24)
22928+
.maxstack 3
22929+
.locals init (int V_0, //x
22930+
(byte, byte)? V_1) //y
22931+
IL_0000: ldc.i4.1
22932+
IL_0001: stloc.0
22933+
IL_0002: ldloca.s V_1
22934+
IL_0004: ldloc.0
22935+
IL_0005: conv.u1
22936+
IL_0006: ldloc.0
22937+
IL_0007: conv.u1
22938+
IL_0008: newobj ""System.ValueTuple<byte, byte>..ctor(byte, byte)""
22939+
IL_000d: call ""(byte, byte)?..ctor((byte, byte))""
22940+
IL_0012: ldloca.s V_1
22941+
IL_0014: call ""(byte, byte) (byte, byte)?.Value.get""
22942+
IL_0019: box ""System.ValueTuple<byte, byte>""
22943+
IL_001e: call ""void System.Console.WriteLine(object)""
22944+
IL_0023: ret
22945+
}
22946+
");
22947+
}
2287522948
}
2287622949
}

0 commit comments

Comments
 (0)