Skip to content

Commit

Permalink
AddSynthesizedRecordMembersIfNecessary - avoid touching members that …
Browse files Browse the repository at this point in the history
…are known to have no effect on the outcome of the function. (#49610)

This avoids unnecessary work and fixes #49286.
  • Loading branch information
AlekseyTs authored Nov 26, 2020
1 parent 1f97e38 commit f8107de
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,14 @@ private void AddSynthesizedRecordMembersIfNecessary(MembersAndInitializersBuilde
var members = ArrayBuilder<Symbol>.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);
Expand Down
66 changes: 66 additions & 0 deletions src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

0 comments on commit f8107de

Please sign in to comment.