Skip to content

Fix MA0046 reporting override events - #1599

Merged
meziantou merged 1 commit into
mainfrom
fix/ma0046-override-events
Sep 23, 2026
Merged

meziantou merged 1 commit into
mainfrom
fix/ma0046-override-events

Conversation

@meziantou

Copy link
Copy Markdown
Owner

What

MA0046 (Use EventHandler to declare events) skipped the interface implementations, but not the overrides, so the same event was reported on the base declaration and on each override, whose type cannot be changed:

abstract class Base
{
    public abstract event System.Action E; // MA0046, expected
}

class Derived : Base
{
    public override event System.Action E; // MA0046, unexpected
}

Expected: 1 diagnostic (on Base.E). Actual: 2 diagnostics.

Fix

The analyzer skips override events, like the interface implementations. docs/Rules/MA0046.md mentions both.

Tests

Added Override to UseEventHandlerOfTAnalyzerTests (failed before the fix). The test class passes on roslyn5.9 (16/16) and roslyn4.8 (16/16).

@meziantou
meziantou marked this pull request as ready for review September 23, 2026 03:59
@meziantou
meziantou merged commit e48ae3f into main Sep 23, 2026
14 checks passed
@meziantou
meziantou deleted the fix/ma0046-override-events branch September 23, 2026 03:59
This was referenced Sep 23, 2026
This was referenced Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant