Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddSynthesizedRecordMembersIfNecessary - avoid touching members that are known to have no effect on the outcome of the function. #49610

Merged
merged 2 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}