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

RS0042 incorrectly firing for ref usage #7128

Closed
jaredpar opened this issue Jan 9, 2024 · 5 comments · Fixed by #7132
Closed

RS0042 incorrectly firing for ref usage #7128

jaredpar opened this issue Jan 9, 2024 · 5 comments · Fixed by #7132
Assignees
Labels
Area-Roslyn.Diagnostics.Analyzers Bug The product is not behaving according to its current intended design False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting
Milestone

Comments

@jaredpar
Copy link
Member

jaredpar commented Jan 9, 2024

Consider the following code in roslyn

        public static ref TemporaryArray<T> AsRef<T>(this in TemporaryArray<T> array)
            => ref Unsafe.AsRef(in array);

This code is not copying a TemporaryArray<T> but just downgrading a in to a ref. This is firing RS0042 which seems incorrect though because there is no copy of the value here, just a change of the ref kind.

@mavasani mavasani added Bug The product is not behaving according to its current intended design Area-Roslyn.Diagnostics.Analyzers False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting labels Jan 10, 2024
@mavasani mavasani added this to the vNext milestone Jan 10, 2024
@sharwell
Copy link
Member

That helper method exists for the sole purpose of avoiding diagnostics. Can you provide a more complete example showing how the error was observed?

@jaredpar
Copy link
Member Author

The error was fired for that exact method. The ref Unsafe.AsRef(in array) is where it fires. You can see in this PR where I had to suppress RS0042 at this location

https://github.com/dotnet/roslyn/pull/71507/files#diff-0e7827689d069ca296c5c6ccf49bbf565e5eb4e6700b3ddd7769916a7b81b1e3

@sharwell
Copy link
Member

Weird. So far I have not been able to reproduce this.

@sharwell
Copy link
Member

sharwell commented Jan 10, 2024

Looks like dotnet/runtime#89736 changed the signature of Unsafe.AsRef to a form that isn't supported by the analyzer. Should be an easy fix.

@jaredpar
Copy link
Member Author

That explains the timing of why I just started getting the analyzer failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Roslyn.Diagnostics.Analyzers Bug The product is not behaving according to its current intended design False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants