We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Version Used: 20241126.6 (b23da04)
Steps to Reproduce:
using System; using System.Diagnostics.CodeAnalysis; var r = F(); Console.WriteLine(r.F.ToString()); static R F() { var r = new R(); ((I)new C()).M(ref r); return r; } interface I { void M(ref R r); } class C : I { public void M([UnscopedRef] ref R r) { r.F = ref r.I; } } ref struct R { public int I; public ref int F; }
Expected Behavior: An error at ((I)new C()).M(ref r); - an error would be reported there if replaced with new C().M(ref r);.
((I)new C()).M(ref r);
new C().M(ref r);
Actual Behavior: No errors. The program accesses an invalid reference at runtime.
The text was updated successfully, but these errors were encountered:
Just so I understand, the problem is just because the implementation is narrowing the escape scope, right? Ie. if you had:
interface I { void M([UnscopedRef] ref R r); } class C : I { public void M(ref R r) { } }
That should be fine, right? Would that still be allowed?
Sorry, something went wrong.
Yes, that should be fine. Per the spec, removing [UnscopedRef] in the interface implementation is allowed.
[UnscopedRef]
Also this section of the spec needs to be updated - it does not consider the "silly cyclic self-assignment":
The compiler will report a diagnostic for unsafe scoped mismatches across overrides, interface implementations, and delegate conversions when: The method returns a ref struct or returns a ref or ref readonly, or the method has a ref or out parameter of ref struct type, and The method has at least one additional ref, in, or out parameter, or a parameter of ref struct type.
The compiler will report a diagnostic for unsafe scoped mismatches across overrides, interface implementations, and delegate conversions when:
ref struct
ref
ref readonly
out
in
jjonescz
Successfully merging a pull request may close this issue.
Version Used: 20241126.6 (b23da04)
Steps to Reproduce:
Expected Behavior: An error at
((I)new C()).M(ref r);
- an error would be reported there if replaced withnew C().M(ref r);
.Actual Behavior: No errors. The program accesses an invalid reference at runtime.
The text was updated successfully, but these errors were encountered: