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

Fix IDE0004 for OverloadResolutionPriority #110207

Closed

Conversation

xtqqczze
Copy link
Contributor

@xtqqczze xtqqczze commented Nov 26, 2024

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 26, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 26, 2024
@stephentoub
Copy link
Member

Thank you, but I do not want to take this change. Even if the compiler ends up preferring to call the ROS overload, it's very non-obvious at the call site. I'd rather leave the casts in place as an obvious indication that a different method is being called rather than it being recursive.

@xtqqczze
Copy link
Contributor Author

@stephentoub Is this behaviour of the IDE0004 analyser desirable in general?

@xtqqczze xtqqczze closed this Nov 26, 2024
@stephentoub
Copy link
Member

@stephentoub Is this behaviour of the IDE0004 analyser desirable in general?

In general, unnecessary casts are unnecessary; they don't cost anything, but they can clutter up the code, and so in general removing them is fine. But in some cases, like this one, the visual indicator of having them is actually a benefit.

@xtqqczze
Copy link
Contributor Author

@stephentoub Is this behaviour of the IDE0004 analyser desirable in general?

In general, unnecessary casts are unnecessary; they don't cost anything, but they can clutter up the code, and so in general removing them is fine. But in some cases, like this one, the visual indicator of having them is actually a benefit.

I mean, the IDE0004 diagnostic is only flagging when OverloadResolutionPriorityAttribute is present.

@stephentoub
Copy link
Member

I mean, the IDE0004 diagnostic is only flagging when OverloadResolutionPriorityAttribute is present.

I don't know what you mean.
image

@xtqqczze
Copy link
Contributor Author

I don't know what you mean.

[OverloadResolutionPriority(-1)]
public static unsafe bool Contains<T>(this Span<T> span, T value) where T : IEquatable<T>? =>
    Contains((ReadOnlySpan<T>)span, value); // IDE0004
//[OverloadResolutionPriority(-1)]
public static unsafe bool Contains<T>(this Span<T> span, T value) where T : IEquatable<T>? =>
    Contains((ReadOnlySpan<T>)span, value); // No IDE0004

@stephentoub
Copy link
Member

By adding the attribute, you're changing what overload is bound. And which overload is bound impacts whether the cast is necessary or not.

@xtqqczze
Copy link
Contributor Author

By adding the attribute, you're changing what overload is bound. And which overload is bound impacts whether the cast is necessary or not.

I understand that adding the attribute changes which overload is bound, and that this affects whether the cast is necessary. My question is whether you believe it is desirable for this diagnostic to be flagged in cases where the cast, while unnecessary, serves to clarify non-obvious behavior (as in this PR).

@stephentoub
Copy link
Member

My question is whether you believe it is desirable for this diagnostic to be flagged in cases where the cast, while unnecessary, serves to clarify non-obvious behavior (as in this PR).

I think it's in the eye of the beholder whether it's non-obvious. I think it makes sense for the rule to flag it, as it's correct that it's technically not required. It's then up to the developer to decide what they prefer.

@xtqqczze
Copy link
Contributor Author

I think it's in the eye of the beholder whether it's non-obvious.

In that case, I'll reopen this PR for other reviewers.

@xtqqczze xtqqczze reopened this Nov 27, 2024
@stephentoub
Copy link
Member

stephentoub commented Nov 27, 2024

I think it's in the eye of the beholder whether it's non-obvious.

In that case, I'll reopen this PR for other reviewers.

As a maintainer of this repo, I do not want this to merge. But thank you.

@xtqqczze xtqqczze deleted the IDE0004/OverloadResolutionPriority branch November 28, 2024 00:54
@xtqqczze xtqqczze changed the title Fx IDE0004 for OverloadResolutionPriority Fix IDE0004 for OverloadResolutionPriority Nov 28, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants