Skip to content
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

Create user-defined-compound-assignment.md #9068

Merged
merged 22 commits into from
Jan 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
83467c1
Create user-defined-compound-assignment.md
AlekseyTs Jan 15, 2025
403387a
Update user-defined-compound-assignment.md
AlekseyTs Jan 15, 2025
299a5aa
Update user-defined-compound-assignment.md
AlekseyTs Jan 15, 2025
7e280b2
Update user-defined-compound-assignment.md
AlekseyTs Jan 15, 2025
1626182
Update user-defined-compound-assignment.md
AlekseyTs Jan 15, 2025
c4a0627
Update user-defined-compound-assignment.md
AlekseyTs Jan 15, 2025
e594409
Update user-defined-compound-assignment.md
AlekseyTs Jan 15, 2025
51743fe
Update user-defined-compound-assignment.md
AlekseyTs Jan 15, 2025
2551064
Update user-defined-compound-assignment.md
AlekseyTs Jan 15, 2025
a42d149
Update user-defined-compound-assignment.md
AlekseyTs Jan 16, 2025
51e7c9e
Update user-defined-compound-assignment.md
AlekseyTs Jan 16, 2025
fbf7ddc
Update user-defined-compound-assignment.md
AlekseyTs Jan 16, 2025
e9c6a46
Update user-defined-compound-assignment.md
AlekseyTs Jan 16, 2025
a20bef0
Update user-defined-compound-assignment.md
AlekseyTs Jan 16, 2025
8d4220d
Update user-defined-compound-assignment.md
AlekseyTs Jan 16, 2025
aeeb6f9
Update user-defined-compound-assignment.md
AlekseyTs Jan 16, 2025
0b93394
Update user-defined-compound-assignment.md
AlekseyTs Jan 17, 2025
b12331f
Update user-defined-compound-assignment.md
AlekseyTs Jan 17, 2025
5309948
Update user-defined-compound-assignment.md
AlekseyTs Jan 17, 2025
c2460dc
Update user-defined-compound-assignment.md
AlekseyTs Jan 21, 2025
7c9bfd1
Update user-defined-compound-assignment.md
AlekseyTs Jan 27, 2025
0f9d65c
Update user-defined-compound-assignment.md
AlekseyTs Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update user-defined-compound-assignment.md
  • Loading branch information
AlekseyTs authored Jan 17, 2025
commit b12331fc1bb370a24cd714834044fd91ce6187ad
14 changes: 7 additions & 7 deletions proposals/user-defined-compound-assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class C1
```

with the current language rules, compound assignment operator `c1 += 1` invokes user defined `+` operator
and then assigns its return value to the local variable `c1`. Note that operator implementation has to allocate
and then assigns its return value to the local variable `c1`. Note that operator implementation must allocate
and return a new instance of `C1`, while, from the consumer's perspective, an in-place change to the original
instance of `C1` instead would work as good (it is not used after the assignment), with an additional benefit of
avoiding an extra allocation.
Expand Down Expand Up @@ -224,9 +224,9 @@ ECMA-335 already "reserved" the following special names for user defined increme
|op_Decrement|`--`|
|op_Increment|`++`|

However it states that CLS compliance requires the operator methods to be non-void static methods with a single parameter,
However, it states that CLS compliance requires the operator methods to be non-void static methods with a single parameter,
i.e. matches what static increment operators are. We should consider relaxing the CLS compliance requirements
to allow the opeators to be void returning parameter-less instance methods.
to allow the operators to be void returning parameter-less instance methods.

### Compound assignment operators
[compound-assignment-operators]: #compound-assignment-operators
Expand Down Expand Up @@ -276,9 +276,9 @@ ECMA-335 already "reserved" the following special names for user defined increme
|op_RightShiftAssignment| right_shift_assignment|
|op_UnsignedRightShiftAssignment|unsigned_right_shift_assignment|

However it states that CLS compliance requires the operator methods to be non-void static methods with two parameters,
However, it states that CLS compliance requires the operator methods to be non-void static methods with two parameters,
i.e. matches what C# binary operators are. We should consider relaxing the CLS compliance requirements
to allow the opeators to be void returning instance methods with a single parameter.
to allow the operators to be void returning instance methods with a single parameter.

### Prefix increment and decrement operators

Expand Down Expand Up @@ -355,7 +355,7 @@ struct S
See https://github.com/dotnet/csharpstandard/blob/draft-v8/standard/expressions.md#12816-postfix-increment-and-decrement-operators

If result of the operation is used or `x` in `x «op»` is not classified as a variable,
the operation is processedb by applying unary operator overload resolution as
the operation is processed by applying unary operator overload resolution as
https://github.com/dotnet/csharpstandard/blob/draft-v8/standard/expressions.md#12816-postfix-increment-and-decrement-operators
currently specifies.
The reason why we are not even trying instance increment operators when result is used, is the fact that,
Expand Down Expand Up @@ -564,5 +564,5 @@ purpose of the method is to modify the instance.

### Should shadowing be allowed?

If a derived class declares a 'compund assignment'/'instance increment' operator with the same signature as one in base,
If a derived class declares a 'compound assignment'/'instance increment' operator with the same signature as one in base,
should we require an `override` modifier?