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

UnscopedRef should not affect code under the old ref safety rules #75828

Open
jjonescz opened this issue Nov 8, 2024 · 0 comments · May be fixed by #75930
Open

UnscopedRef should not affect code under the old ref safety rules #75828

jjonescz opened this issue Nov 8, 2024 · 0 comments · May be fixed by #75930

Comments

@jjonescz
Copy link
Member

jjonescz commented Nov 8, 2024

Version Used: .NET 9 RC2

Steps to Reproduce:

Compile with C# 10 and TFM net6.0:

struct S
{
    public int F;

    [UnscopedRef] public ref int Ref() => ref F;
}

namespace System.Diagnostics.CodeAnalysis
{
    [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
    public sealed class UnscopedRefAttribute : Attribute
    {
    }
}

Expected Behavior: Error at ref F same as if the UnscopedRef attribute wasn't present, because the code should use the old ref safety rules when compiled with C# 10 and TFM net6.0.

error CS8170: Struct members cannot return 'this' or other instance members by reference

Actual Behavior: No errors.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 8, 2024
@jaredpar jaredpar added this to the 17.13 milestone Nov 11, 2024
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 12, 2024
@arunchndr arunchndr modified the milestones: 17.13, 17.13 P2 Nov 13, 2024
@jjonescz jjonescz linked a pull request Nov 15, 2024 that will close this issue
@jjonescz jjonescz changed the title UnscopedRef affects C# 10 code UnscopedRef should not affect code under the old ref safety rules Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants