Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[API Proposal]: New user-defined operator names #114930

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

Open
AlekseyTs opened this issue Apr 22, 2025 · 5 comments
Open

[API Proposal]: New user-defined operator names #114930

AlekseyTs opened this issue Apr 22, 2025 · 5 comments
Labels
api-approved API was approved in API review, it can be implemented area-Meta
Milestone

Comments

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 22, 2025

Background and motivation

New C# language feature adds ability to declare custom +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=, >>>= operators, including checked forms for +=, -=, *=, /=. ECMA-335 already reserves names for non-checked assignment operators, but not for checked assignment operators.
The feature also adds ability to declare custom instance (vs. static) ++, -- operators, including checked forms.

API Proposal

Reserve the following names:

Name Operator
op_DecrementAssignment instance --
op_IncrementAssignment instance ++
op_CheckedDecrementAssignment instance checked --
op_CheckedIncrementAssignment instance checked ++
op_CheckedAdditionAssignment checked '+='
op_CheckedSubtractionAssignment checked '-='
op_CheckedMultiplicationAssignment checked '*='
op_CheckedDivisionAssignment checked '/='

The names follow the pattern previously used for Checked user-defined operators feature.

ECMA-335 already reserves the following names for non-checked operators:

Name Operator
op_AdditionAssignment '+='
op_SubtractionAssignment '-='
op_MultiplicationAssignment '*='
op_DivisionAssignment '/='

API Usage

The names will be used by compilers for methods implementing the operators.

Alternative Designs

N/A

Risks

N/A

@AlekseyTs AlekseyTs added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Apr 22, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 22, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 22, 2025
@AlekseyTs AlekseyTs added this to the 10.0.0 milestone Apr 22, 2025
@AlekseyTs AlekseyTs added the api-ready-for-review API is ready for review, it is NOT ready for implementation label Apr 22, 2025
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Apr 22, 2025
@teo-tsirpanis teo-tsirpanis added area-Meta and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 23, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

@AlekseyTs AlekseyTs added the blocking Marks issues that we want to fast track in order to unblock other important work label May 2, 2025
@AlekseyTs
Copy link
Contributor Author

CC @tannergooding

@tannergooding tannergooding removed the api-suggestion Early API idea and discussion, it is NOT ready for implementation label May 2, 2025
@bartonjs
Copy link
Member

bartonjs commented May 6, 2025

Video

Looks good as proposed

There was discussion about "Assignment" vs some other token ("Self"?) for the instance increment/decrement, but we stuck with the proposed "Assignment" in the end.

Name Operator
op_DecrementAssignment instance --
op_IncrementAssignment instance ++
op_CheckedDecrementAssignment instance checked --
op_CheckedIncrementAssignment instance checked ++
op_CheckedAdditionAssignment checked '+='
op_CheckedSubtractionAssignment checked '-='
op_CheckedMultiplicationAssignment checked '*='
op_CheckedDivisionAssignment checked '/='

@bartonjs bartonjs added api-approved API was approved in API review, it can be implemented and removed blocking Marks issues that we want to fast track in order to unblock other important work api-ready-for-review API is ready for review, it is NOT ready for implementation labels May 6, 2025
@fubar-coder
Copy link
Contributor

Just curious, is there a need for op_CheckedUnaryNegation?

@AlekseyTs
Copy link
Contributor Author

Just curious, is there a need for op_CheckedUnaryNegation?

Not for this feature. And I think this name already got reserved when we were adding support for checked user-defined operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved in API review, it can be implemented area-Meta
Projects
None yet
Development

No branches or pull requests

5 participants