-
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
Local constant declarations can specify const multiple times #6929
Conversation
@dotnet-bot retest prtest/win/dbg/unit64 please |
tag @dotnet/roslyn-compiler |
okay to test |
LGTM |
@@ -7996,6 +7996,12 @@ private void ParseDeclarationModifiers(SyntaxListBuilder list) | |||
mod = this.AddError(mod, ErrorCode.ERR_BadMemberFlag, mod.Text); | |||
} | |||
|
|||
// check for duplicates, can only be const |
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.
Comments shouldn't be used to break apart if / else
blocks. Please move the comment into the else block.
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.
@jaredpar: Thanks, I wasn't sure about this :) Was just an if
initially. Edit: Holy Batman, I just noticed how big that file is!
👍 modulo the style comment. |
else if (list.Any(mod.Kind)) | ||
{ | ||
// check for duplicates, can only be const | ||
mod = this.AddError(mod, ErrorCode.ERR_TypeExpected, mod.Text); |
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 it would be better to report more specific error, i.e. duplicate modifier.
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.
@AlekseyTs: Agreed, but I for now I just recreated the behavior of fields. The previous compiler reports a different error if I recall correctly, but for consistency I chose Roslyn's behavior. Edit: I cant seem to replicate the behavior I saw earlier on old compiler. Error was CS1041: Identifier expected, 'const' is a keyword'
. (Or perhaps that was another case?)
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.
Given that this function is only used to parse a local declaration, I agree that ERR_TypeExpected is in agreement with the language grammar.
LGTM |
test eta please |
Merging this in, thanks again for another contribution! |
Local constant declarations can specify const multiple times
Fixes #6761.
Matches behavior for const field declarations.
Side note: There should be a
ParseAndValidate
that ignores additional errors. Sometimes the extra errors make a test needlessly complex.