Skip to content

Commit b49979a

Browse files
author
Julien Couvreur
committed
Add tests for default value being used or not
1 parent c620d4a commit b49979a

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15748,11 +15748,11 @@ public static void Main()
1574815748

1574915749
var comp = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularPreview, options: TestOptions.DebugExe);
1575015750
comp.VerifyDiagnostics();
15751-
CompileAndVerify(comp, expectedOutput: "42");
15751+
CompileAndVerify(comp, expectedOutput: "42", verify: Verification.Skipped /* init-only */);
1575215752
}
1575315753

1575415754
[Fact, WorkItem(45008, "https://github.com/dotnet/roslyn/issues/45008")]
15755-
public void PositionalMemberDefaultValue_AndPropertyInitializer()
15755+
public void PositionalMemberDefaultValue_AndPropertyWithInitializer()
1575615756
{
1575715757
var src = @"
1575815758
record R(int P = 1)
@@ -15768,7 +15768,7 @@ public static void Main()
1576815768
";
1576915769
var comp = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularPreview, options: TestOptions.DebugExe);
1577015770
comp.VerifyDiagnostics();
15771-
var verifier = CompileAndVerify(comp, expectedOutput: "42");
15771+
var verifier = CompileAndVerify(comp, expectedOutput: "42", verify: Verification.Skipped /* init-only */);
1577215772

1577315773
verifier.VerifyIL("R..ctor(int)", @"
1577415774
{
@@ -15781,6 +15781,69 @@ .maxstack 2
1578115781
IL_0009: call ""object..ctor()""
1578215782
IL_000e: nop
1578315783
IL_000f: ret
15784+
}");
15785+
}
15786+
15787+
[Fact, WorkItem(45008, "https://github.com/dotnet/roslyn/issues/45008")]
15788+
public void PositionalMemberDefaultValue_AndPropertyWithoutInitializer()
15789+
{
15790+
var src = @"
15791+
record R(int P = 42)
15792+
{
15793+
public int P { get; init; }
15794+
15795+
public static void Main()
15796+
{
15797+
var r = new R();
15798+
System.Console.Write(r.P);
15799+
}
15800+
}
15801+
";
15802+
var comp = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularPreview, options: TestOptions.DebugExe);
15803+
comp.VerifyDiagnostics();
15804+
var verifier = CompileAndVerify(comp, expectedOutput: "0", verify: Verification.Skipped /* init-only */);
15805+
15806+
verifier.VerifyIL("R..ctor(int)", @"
15807+
{
15808+
// Code size 8 (0x8)
15809+
.maxstack 1
15810+
IL_0000: ldarg.0
15811+
IL_0001: call ""object..ctor()""
15812+
IL_0006: nop
15813+
IL_0007: ret
15814+
}");
15815+
}
15816+
15817+
[Fact, WorkItem(45008, "https://github.com/dotnet/roslyn/issues/45008")]
15818+
public void PositionalMemberDefaultValue_AndPropertyWithInitializer_CopyingParameter()
15819+
{
15820+
var src = @"
15821+
record R(int P = 42)
15822+
{
15823+
public int P { get; init; } = P;
15824+
15825+
public static void Main()
15826+
{
15827+
var r = new R();
15828+
System.Console.Write(r.P);
15829+
}
15830+
}
15831+
";
15832+
var comp = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularPreview, options: TestOptions.DebugExe);
15833+
comp.VerifyDiagnostics();
15834+
var verifier = CompileAndVerify(comp, expectedOutput: "42", verify: Verification.Skipped /* init-only */);
15835+
15836+
verifier.VerifyIL("R..ctor(int)", @"
15837+
{
15838+
// Code size 15 (0xf)
15839+
.maxstack 2
15840+
IL_0000: ldarg.0
15841+
IL_0001: ldarg.1
15842+
IL_0002: stfld ""int R.<P>k__BackingField""
15843+
IL_0007: ldarg.0
15844+
IL_0008: call ""object..ctor()""
15845+
IL_000d: nop
15846+
IL_000e: ret
1578415847
}");
1578515848
}
1578615849
}

0 commit comments

Comments
 (0)