Allow adding scoped or removing [UnscopedRef] for override, interface implementation, or delegate conversion#63656
Allow adding scoped or removing [UnscopedRef] for override, interface implementation, or delegate conversion#63656cston merged 10 commits intodotnet:mainfrom
scoped or removing [UnscopedRef] for override, interface implementation, or delegate conversion#63656Conversation
|
/azp run |
|
Azure Pipelines failed to run 2 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s), but failed to run 1 pipeline(s). |
|
This also fixes an issue introduced in #63461 that prevents moving to the latest compiler. Specifically, the following should compile without errors: Compile with public delegate void D1<T>(out T t1);Compile with class Program
{
static void F1(out int i1) { i1 = 0; }
static void Main()
{
// error CS8986: The 'scoped' modifier of parameter 'i1' doesn't match target 'D1<int>'
D1<int> d1 = F1;
}
} |
|
@dotnet/roslyn-compiler, please review. |
| { | ||
| D1 dA = M2; | ||
| D2 d2 = M1; | ||
| D1 d1 = M2; |
There was a problem hiding this comment.
Can we please make the numbers line up with DX and MX?
There was a problem hiding this comment.
I was numbering Dx and Mx with the same x for the matching signature. That seemed the most useful to me.
There was a problem hiding this comment.
I suppose someone will be confused, no matter what you name these.
| D1 dA = M2; | ||
| D2 d2 = M1; | ||
| D1 d1 = M2; | ||
| D2 d2 = M1; // 1 |
There was a problem hiding this comment.
it would be helpful to add these trailing comments on all the tests where the diagnostics changed. Also, it looks like the comments are incomplete in this test. I would expect comments for declarations of 'M3' and 'M5'.
There was a problem hiding this comment.
I would expect comments for declarations of 'M3' and 'M5'.
I thought it would be clearer to have comments for the diagnostics related to scoped mismatch only.
it would be helpful to add these trailing comments on all the tests where the diagnostics changed.
It looks like there are comments on most if not all of the ERR_ScopedMismatch* errors. Let me know if I've missed some, thanks.
|
@333fred, @RikkiGibson, please review since this PR has been updated to: report diagnostics for unsafe differences only; and report warnings rather than errors for modules compiled with |
| } | ||
| else if (parameters.Any(p => (p.RefKind is RefKind.Ref or RefKind.Out) && p.Type.IsRefLikeType)) | ||
| { | ||
| nRefParametersRequired = 2; // including the parameter found above |
There was a problem hiding this comment.
I wasn't sure if this will need to be modified to account for the upcoming ReturnOnlyScope change. Perhaps at that time it would be worth changing this to try an approach where we simulate the base calling into the derived and see if escape rules are satisfied.
class Base
{
public virtual Span<byte> M(scoped ref byte input)
{
// if we could call Derived.M like this, would we satisfy escape rules?
return Derived.M(ref input);
}
}
class Derived : Base
{
public override Span<byte> M(ref byte input)
{
}
}|
@dotnet/roslyn-compiler it would be great to get this in soon, as the many diagnostic changes are prone to cause conflicts with other PRs. |
There was a problem hiding this comment.
Nit: remember that we have raw strings, and you can do $$""" :).
See low-level-struct-improvements.md.
Fixes #62340.
Fixes #63761.