未验证 提交 585e5693 编写于 作者: Y Youssef Victor 提交者: GitHub

Exclude constant and static fields from record's PrintMembers (#47868)

上级 8d44c7fd
......@@ -209,7 +209,7 @@ static BoundStatement makeAppendString(SyntheticBoundNodeFactory F, BoundParamet
static bool isPrintable(Symbol m)
{
if (m.DeclaredAccessibility != Accessibility.Public)
if (m.DeclaredAccessibility != Accessibility.Public || m.IsStatic)
{
return false;
}
......
......@@ -25630,5 +25630,55 @@ public static void Main()
CompileAndVerify(comp, expectedOutput: "4243", verify: Verification.Skipped /* init-only */);
}
[Fact]
[WorkItem(47867, "https://github.com/dotnet/roslyn/issues/47867")]
public void ToString_RecordWithStaticMembers()
{
var src = @"
var c1 = new C1(42);
System.Console.Write(c1.ToString());
record C1(int I1)
{
public static int field1 = 44;
public const int field2 = 44;
public static int P1 { set { } }
public static int P2 { get { return 1; } set { } }
public static int P3 { get { return 1; } }
}
";
var compDebug = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, options: TestOptions.DebugExe);
var compRelease = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, options: TestOptions.ReleaseExe);
CompileAndVerify(compDebug, expectedOutput: "C1 { I1 = 42 }", verify: Verification.Skipped /* init-only */);
compDebug.VerifyEmitDiagnostics();
CompileAndVerify(compRelease, expectedOutput: "C1 { I1 = 42 }", verify: Verification.Skipped /* init-only */);
compRelease.VerifyEmitDiagnostics();
}
[Fact]
[WorkItem(47867, "https://github.com/dotnet/roslyn/issues/47867")]
public void ToString_NestedRecord()
{
var src = @"
var c1 = new Outer.C1(42);
System.Console.Write(c1.ToString());
public class Outer
{
public record C1(int I1);
}
";
var compDebug = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, options: TestOptions.DebugExe);
var compRelease = CreateCompilation(new[] { src, IsExternalInitTypeDefinition }, options: TestOptions.ReleaseExe);
CompileAndVerify(compDebug, expectedOutput: "C1 { I1 = 42 }", verify: Verification.Skipped /* init-only */);
compDebug.VerifyEmitDiagnostics();
CompileAndVerify(compRelease, expectedOutput: "C1 { I1 = 42 }", verify: Verification.Skipped /* init-only */);
compRelease.VerifyEmitDiagnostics();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册