From 3e42f981147108fa1a31971f21b35e3c30fc2058 Mon Sep 17 00:00:00 2001 From: AlekseyTs Date: Tue, 24 Nov 2020 16:35:56 -0800 Subject: [PATCH 1/2] AddSynthesizedRecordMembersIfNecessary - avoid touching members that are known to have no effect on the outcome of the function. This avoids unnecessary work and fixes #49286. --- .../Source/SourceMemberContainerSymbol.cs | 8 +++ .../Test/Symbol/Symbols/Source/RecordTests.cs | 66 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs index 5be7d7f72f8f9..814183255f432 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs @@ -3034,6 +3034,14 @@ private void AddSynthesizedRecordMembersIfNecessary(MembersAndInitializersBuilde var members = ArrayBuilder.GetInstance(builder.NonTypeNonIndexerMembers.Count + 1); foreach (var member in builder.NonTypeNonIndexerMembers) { + switch(member) + { + case FieldSymbol: + case EventSymbol: + case MethodSymbol { MethodKind: not (MethodKind.Ordinary or MethodKind.Constructor) }: + continue; + } + if (!memberSignatures.ContainsKey(member)) { memberSignatures.Add(member, member); diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs index 3c9bfe700fdba..81534c2b48141 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs @@ -1566,5 +1566,71 @@ .maxstack 1 IL_001b: ret }"); } + + [Fact] + [WorkItem(49286, "https://github.com/dotnet/roslyn/issues/49286")] + public void RecordWithEventImplicitlyImplementingAnInterface() + { + var src = @" +using System; + +public interface I1 +{ + event Action E1; +} + +public record R1 : I1 +{ + public event Action E1 { add { } remove { } } +} +"; + + var comp = CreateCompilation(src); + comp.VerifyEmitDiagnostics(); + } + + [Fact] + [WorkItem(49286, "https://github.com/dotnet/roslyn/issues/49286")] + public void RecordWithPropertyImplicitlyImplementingAnInterface() + { + var src = @" +using System; + +public interface I1 +{ + Action P1 { get; set; } +} + +public record R1 : I1 +{ + public Action P1 { get; set; } +} +"; + + var comp = CreateCompilation(src); + comp.VerifyEmitDiagnostics(); + } + + [Fact] + [WorkItem(49286, "https://github.com/dotnet/roslyn/issues/49286")] + public void RecordWithMethodImplicitlyImplementingAnInterface() + { + var src = @" +using System; + +public interface I1 +{ + Action M1(); +} + +public record R1 : I1 +{ + public Action M1() => throw null; +} +"; + + var comp = CreateCompilation(src); + comp.VerifyEmitDiagnostics(); + } } } From 736bddaff88748a4e284258bdb380bb9b70220d5 Mon Sep 17 00:00:00 2001 From: AlekseyTs Date: Tue, 24 Nov 2020 17:15:39 -0800 Subject: [PATCH 2/2] Fix formatting --- .../Portable/Symbols/Source/SourceMemberContainerSymbol.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs index 814183255f432..9d22f94f23437 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs @@ -3034,7 +3034,7 @@ private void AddSynthesizedRecordMembersIfNecessary(MembersAndInitializersBuilde var members = ArrayBuilder.GetInstance(builder.NonTypeNonIndexerMembers.Count + 1); foreach (var member in builder.NonTypeNonIndexerMembers) { - switch(member) + switch (member) { case FieldSymbol: case EventSymbol: