Disallow applying RequiresLocation and Out attributes to ref readonly parameters in source#68871
Conversation
66dee83 to
356051d
Compare
| <value>An in parameter cannot have the Out attribute.</value> | ||
| </data> | ||
| <data name="ERR_OutAttrOnRefReadonlyParam" xml:space="preserve"> | ||
| <value>A ref readonly parameter cannot have the Out attribute.</value> |
| ReservedAttributes.DynamicAttribute | | ||
| ReservedAttributes.IsReadOnlyAttribute | | ||
| // PROTOTYPE: RequiresLocationAttribute | ||
| ReservedAttributes.RequiresLocationAttribute | |
There was a problem hiding this comment.
I think IsReadOnly has wider semantics - for example, returns can be readonly, but they probably cannot be RequiresLocation.
There was a problem hiding this comment.
I think IsReadOnly has wider semantics - for example, returns can be readonly, but they probably cannot be RequiresLocation.
Looking at IsByRefLikeAttribute, compiler synthesizes it only for named types, but ReservedAttributes.IsByRefLikeAttribute is checked for a wide set of symbols. I don't think this is a blocking issue for this PR, but let's confirm with LDM whether we want proactively prohibit application of the attribute in other contexts in order to preserve future design space.
There was a problem hiding this comment.
Added to section "alternatives pending LDM review": dotnet/csharplang#7328
| void M2([RequiresLocation] in int p) { } | ||
| void M3([RequiresLocation] ref int p) { } | ||
| void M4([RequiresLocation] int p) { } | ||
| [return: RequiresLocation] int M5() => 5; |
There was a problem hiding this comment.
No, but that's because IsReadOnly can be emitted there by the compiler. RequiresLocation is different.
| """; | ||
|
|
||
| CreateCompilation(source).VerifyDiagnostics( | ||
| // (1,1): hidden CS8019: Unnecessary using directive. |
|
Done with review pass (commit 1) |
Yes, but note that this isn't changed in this PR, it's only CodeFlow's diff displaying it as an addition. In reply to: 1621881653 Refers to: src/Compilers/CSharp/Test/Emit2/Semantics/RefReadonlyParameterTests.cs:138 in 356051d. [](commit_id = 356051d, deletion_comment = False) |
RequiresLocationAttribute to parameters in sourceRequiresLocation and Out attributes to ref readonly parameters in source
Speclet: https://github.com/dotnet/csharplang/blob/cd336064a26a43c31c1164ef7cd3f5feb4420d20/proposals/ref-readonly-parameters.md
Test plan: #68056