Include [UnscopedRef] parameter attributes in synthesized delegate types#66035
Include [UnscopedRef] parameter attributes in synthesized delegate types#66035cston merged 7 commits intodotnet:release/dev17.5from
Conversation
33e6860 to
1a661f6
Compare
| internal sealed override DeclarationScope EffectiveScope => _scope; | ||
|
|
||
| internal sealed override bool HasUnscopedRefAttribute => false; | ||
| internal abstract override bool HasUnscopedRefAttribute { get; } |
| case WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor: | ||
| case WellKnownMember.System_Runtime_CompilerServices_IteratorStateMachineAttribute__ctor: | ||
| case WellKnownMember.System_Runtime_CompilerServices_AsyncIteratorStateMachineAttribute__ctor: | ||
| case WellKnownMember.System_Diagnostics_CodeAnalysis_UnscopedRefAttribute__ctor: |
There was a problem hiding this comment.
It looks like we are not testing effect of this change. Also, I think that, unless we have a compelling scenario that we would like to enable, it might be better to detect the lack of the API and report an error instead of silently dropping the attribute. We already do this for default value and param array synthesized attributes.
| { | ||
| if (field.HasUnscopedRefAttribute) | ||
| { | ||
| return false; |
There was a problem hiding this comment.
[UnscopedRef] parameters should be uncommon, so perhaps we should hold off making that change for now.
| AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_ParamArrayAttribute__ctor)); | ||
| } | ||
|
|
||
| if (this.HasUnscopedRefAttribute && this.ContainingSymbol is SynthesizedDelegateInvokeMethod) |
There was a problem hiding this comment.
Left as is for now, but switched the order of the two if statements to avoid a conflict with the main branch.
|
|
||
| [Fact] | ||
| [WorkItem(63565, "https://github.com/dotnet/roslyn/issues/63565")] | ||
| public void SynthesizedDelegateTypes_UnscopedRefAttribute_01() |
|
Done with review pass (commit 1) |
| { | ||
| Binder.AddUseSiteDiagnosticForSynthesizedAttribute( | ||
| Compilation, | ||
| checkWellKnownMemberAvailable( |
There was a problem hiding this comment.
Updated, thanks. (I'm not sure why I'd overlooked AddUseSiteDiagnosticForSynthesizedAttribute previously.)
| <>f__AnonymousDelegate0 | ||
| <>F{00000015}`3[System.Int32,System.Int32,System.Int32] | ||
| """); | ||
| verifier.VerifyTypeIL("<>f__AnonymousDelegate1", |
There was a problem hiding this comment.
f__AnonymousDelegate0 is inferred from a method group without [UnscopedRef].
There was a problem hiding this comment.
It looks like we are using the attribute on different parameters (first and the second)
There was a problem hiding this comment.
Sorry, I'd overlooked the differently named delegate type before <>f__AnonymousDelegate0. Added <>f__AnonymousDelegate0.
| comp = CreateCompilation(sourceB, references: new[] { refA }, targetFramework: TargetFramework.Net60); | ||
| comp.VerifyEmitDiagnostics( | ||
| // (6,17): error CS0656: Missing compiler required member 'System.Diagnostics.CodeAnalysis.UnscopedRefAttribute..ctor' | ||
| // var d = A.F; |
There was a problem hiding this comment.
|
|
||
| comp = CreateCompilation(sourceB, references: new[] { refA }, targetFramework: TargetFramework.Net60); | ||
| comp.VerifyEmitDiagnostics( | ||
| // (6,17): error CS0656: Missing compiler required member 'System.Diagnostics.CodeAnalysis.UnscopedRefAttribute..ctor' |
| var d1 = F1; | ||
| var d2 = F2; | ||
| var d3 = F3; | ||
| var d4 = ([UnscopedRef] ref int x, ref int y) => ref x; |
|
Done with review pass (commit 6) |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Fixes #63565
VSO bug #1715794