-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Support declaration of instance increment operators #76991
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
Support declaration of instance increment operators #76991
Conversation
|
|
||
| this.CheckUnsafeModifier(declarationModifiers, diagnostics); | ||
|
|
||
| bool isIncrementDecrement = syntax is OperatorDeclarationSyntax { OperatorToken.RawKind: (int)SyntaxKind.PlusPlusToken or (int)SyntaxKind.MinusMinusToken }; |
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: this pattern is done 3 times in this file, consider extracting a helper. #Resolved
| <value>User-defined operator '{0}' must be declared public</value> | ||
| </data> | ||
| <data name="ERR_BadIncrementOpArgs" xml:space="preserve"> | ||
| <value>Overloaded instance increment operator '{0}' takes no parameters</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.
Consider using the imperative form here: must take no parameters, for example. Right now, it's unclear from the wording how many parameters are supposed to be present. #Resolved
| { | ||
| Binder.CheckFeatureAvailability(syntax, MessageID.IDS_FeatureUserDefinedCompoundAssignmentOperators, diagnostics, ((OperatorDeclarationSyntax)syntax).OperatorToken.GetLocation()); | ||
|
|
||
| if (parameterCount is not (0 or 2)) |
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's the reason for allowing 2 here? I would think that we should prefer giving errors about the specific operator the user typed out, rather than presuming the user meant to type a binary operator instead. #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.
What's the reason for allowing 2 here? I would think that we should prefer giving errors about the specific operator the user typed out, rather than presuming the user meant to type a binary operator instead.
Parser reports an error for the 2 parameters case. I don't want to move all that parameter checking out of the parser, so I just made the smallest change to let "might be a success" cases through in the parser.
src/Compilers/CSharp/Test/Emit3/Symbols/UserDefinedCompoundAssignmentOperatorsTests.cs
Show resolved
Hide resolved
|
@cston, @dotnet/roslyn-compiler For the second review |
3d90c17
into
dotnet:features/UserDefinedCompoundAssignment
No description provided.