-
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
Allow parsing ref readonly
modifier
#68164
Allow parsing ref readonly
modifier
#68164
Conversation
8e975a7
to
b10e188
Compare
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.
It looks like an alternative syntax is still being discussed (using an attribute), so I'll hold off review until we close on that
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) with some small test suggestions
@jcouv, @AlekseyTs PTAL |
ref readonly
modifierref readonly
modifier
@jcouv @AlekseyTs @dotnet/roslyn-compiler please review |
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
Done with review pass (commit 7) |
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit2/Semantics/RefReadonlyParameterTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
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 11), assuming CI is passing
using Microsoft.CodeAnalysis.CSharp.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Semantics |
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.
Consider using file-scoped namespace (we tend to do that for new test files)
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.
Consider using file-scoped namespace (we tend to do that for new test files)
I do not think there is a requirement like this. Also, I personally prefer the block-like namespaces.
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.
Indeed, there's no requirement. The main reason I advocate this is because test files tend to have long lines (such as diagnostics).
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.
The main reason I advocate this is because test files tend to have long lines (such as diagnostics).
I dislike this form of namespaces no matter what.
{ | ||
diagnostics.Add(ErrorCode.ERR_RefReadOnlyWrongOrdering, modifier); | ||
} | ||
else if (seenRef) |
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.
Do we need this condition? #Closed
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.
Do we need this condition?
It makes an observable difference and, in my opinion, improves quality of diagnostics.
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.
It looks like one test would be affected: params ref readonly
. I think you're correct, this check reduces cascaded diagnostics in such scenario.
Then my problem is with how the variable is named, it would be better as "seenValidRef". That said, previous variables seem to suffer the same problem, so it's fine to leave.
else if (seenRef) | ||
{ | ||
Binder.CheckFeatureAvailability(modifier, MessageID.IDS_FeatureRefReadonlyParameters, diagnostics); | ||
seenReadonly = true; |
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.
nit: Should we unconditionally set seenReadonly
? #Closed
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.
Should we unconditionally set
seenReadonly
?
If there is a good enough reason to do that. However, the tests do not show that. If you have a specific scenario in mind, it would be worth looking at.
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.
What is the reason to set seenReadonly
conditionally?
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.
What is the reason to set seenReadonly conditionally?
It does not look useful to set it in any other condition. Other cases do not look at the value. An error that readonly
it is not preceded by ref
is much better than an error about a duplicate, in my opinion.
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.
FWIW, this is the difference: 8cdd541
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.
Basically readonly
means nothing unless it is part of ref readonly
and the ref
is actually not ignored.
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 11)
Speclet: https://github.com/dotnet/csharplang/blob/0c269d235e0687419c1ec69743fb51cea8b4d466/proposals/ref-readonly-parameters.md
Test plan: #68056