Skip to content

Fix RemoveImpl nullability#129661

Open
MichalPetryka wants to merge 5 commits into
dotnet:mainfrom
MichalPetryka:removeimpl-null
Open

Fix RemoveImpl nullability#129661
MichalPetryka wants to merge 5 commits into
dotnet:mainfrom
MichalPetryka:removeimpl-null

Conversation

@MichalPetryka

Copy link
Copy Markdown
Contributor

RemoveImpl accepts null just like CombineImpl does.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 20, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

protected virtual Delegate CombineImpl(Delegate? d) => throw new MulticastNotSupportedException(SR.Multicast_Combine);

protected virtual Delegate? RemoveImpl(Delegate d) => d.Equals(this) ? null : this;
protected virtual Delegate? RemoveImpl(Delegate? d) => Equals(d) ? null : this;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't change behaviour in practice since all runtimes override the method.

@jkotas jkotas Jun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 methods cannot be overridden by user code either. Would it be possible to make them non-virtual instead of this? Follow the same pattern as HasSingleTarget for now, ideally we would move the code from Multicast to Delegate to avoid the forwarder, but that should be its own PR.

Making these 3 methods non-virtual would save 3 virtual slots in every delegate type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're a part of the API contract in ref assembly so we can't remove them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine to change the ref assemblies as long as the change is non-breaking. Can you think about a scenario that would be broken by removing virtual on these methods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine to change the ref assemblies as long as the change is non-breaking. Can you think about a scenario that would be broken by removing virtual on these methods?

One I can think of is that creating a closed delegate to it would now be different between Delegate and MulticastDelegate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Reflection community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants