-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Disallow applying RequiresLocation
and Out
attributes to ref readonly
parameters in source
#68871
Disallow applying RequiresLocation
and Out
attributes to ref readonly
parameters in source
#68871
Conversation
66dee83
to
356051d
Compare
@@ -5878,6 +5878,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
<data name="ERR_OutAttrOnInParam" xml:space="preserve"> | |||
<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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -802,7 +802,7 @@ protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttribut | |||
else if (ReportExplicitUseOfReservedAttributes(in arguments, | |||
ReservedAttributes.DynamicAttribute | | |||
ReservedAttributes.IsReadOnlyAttribute | | |||
// PROTOTYPE: RequiresLocationAttribute | |||
ReservedAttributes.RequiresLocationAttribute | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 1)
Speclet: https://github.com/dotnet/csharplang/blob/cd336064a26a43c31c1164ef7cd3f5feb4420d20/proposals/ref-readonly-parameters.md
Test plan: #68056