Skip to content
Closed
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 @@ -3976,12 +3976,25 @@ private static void MergePartialMembers(
{
membersBySignature.Clear();

// Track if this name has any accessors to avoid false diagnostics for methods with the same name
bool hasAccessors = false;

if (pair.Value is ArrayBuilder<Symbol> arrayBuilder)
{
foreach (var symbol in arrayBuilder)
{
Debug.Assert(symbol.IsPartialMember());

// Skip accessors from signature comparison - they are handled by their associated member.
// Comparing accessor signatures would trigger computation of parameter types,
// which for event accessors requires checking IsWindowsRuntimeEvent, potentially causing
// infinite recursion during member initialization.
if (symbol is SourcePropertyAccessorSymbol or SourceEventAccessorSymbol)
{
hasAccessors = true;
continue;
}

if (!membersBySignature.TryGetValue(symbol, out var prev))
{
membersBySignature.Add(symbol, symbol);
Expand Down Expand Up @@ -4024,7 +4037,15 @@ private static void MergePartialMembers(
{
var symbol = (Symbol)pair.Value;
Debug.Assert(symbol.IsPartialMember());
membersBySignature.Add(symbol, symbol);

if (symbol is SourcePropertyAccessorSymbol or SourceEventAccessorSymbol)
{
hasAccessors = true;
}
else
{
membersBySignature.Add(symbol, symbol);
}
}

foreach (var symbol in membersBySignature.Values)
Expand All @@ -4033,7 +4054,8 @@ private static void MergePartialMembers(
{
case SourceOrdinaryMethodSymbol method:
// partial implementations not paired with a definition
if (method.IsPartialImplementation && method.OtherPartOfPartial is null)
// Skip diagnostic if there are accessors with the same name (e.g., partial method get_P() coexisting with property P's accessor)
if (!hasAccessors && method.IsPartialImplementation && method.OtherPartOfPartial is null)
{
diagnostics.Add(ErrorCode.ERR_PartialMethodMustHaveLatent, method.GetFirstLocation(), method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3740,4 +3740,29 @@ [Obsolete] void M() { }
// [method: Obsolete] public partial event Action H;
Diagnostic(ErrorCode.ERR_AttributeNotOnEventAccessor, "Obsolete").WithArguments("System.ObsoleteAttribute", "class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate").WithLocation(35, 14));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76879")]
public void PartialEventImplementingInterface_NoStackOverflow()
{
var source = """
using System;

internal interface IC
{
event EventHandler E;
}

partial class C : IC
{
public partial event EventHandler E;
}

partial class C
{
public partial event EventHandler E { add { } remove { } }
}
""";
var comp = CreateCompilation(source);
comp.VerifyDiagnostics();
}
}
Loading