Proposed changes to ECMA 335 for checked user-defined operators (#66714)
authorAlekseyTs <AlekseyTs@users.noreply.github.com>
Wed, 6 Apr 2022 13:54:22 +0000 (06:54 -0700)
committerGitHub <noreply@github.com>
Wed, 6 Apr 2022 13:54:22 +0000 (06:54 -0700)
commit424a09cb81c678fb1ba1c27211b80aba2de070ad
tree8190ebdb1e53a7d7cde95a5090d811eda625d312
parent74f58586d6165e4c8c7a33fde2030024d502bf7c
Proposed changes to ECMA 335 for checked user-defined operators (#66714)

C# now supports defining `checked` variants of the following user-defined operators so that users can opt into or out of overflow behavior as appropriate:
*  The `++` and `--` unary operators [§11.7.14](https://github.com/dotnet/csharpstandard/blob/draft-v6/standard/expressions.md#11714-postfix-increment-and-decrement-operators) and [§11.8.6](https://github.com/dotnet/csharpstandard/blob/draft-v6/standard/expressions.md#1186-prefix-increment-and-decrement-operators).
*  The `-` unary operator [§11.8.3](https://github.com/dotnet/csharpstandard/blob/draft-v6/standard/expressions.md#1183-unary-minus-operator).
*  The `+`, `-`, `*`, and `/` binary operators [§11.9](https://github.com/dotnet/csharpstandard/blob/draft-v6/standard/expressions.md#119-arithmetic-operators).
*  Explicit conversion operators.

Motivation:
There is no way for a user to declare a type and support both checked and unchecked versions of an operator. This makes it hard to port various algorithms to use the proposed `generic math` interfaces exposed by the libraries team. Likewise, this makes it impossible to expose a type such as `Int128` or `UInt128` without the language simultaneously shipping its own support to avoid breaking changes.

This change adds names for the new checked operators to the specification.
docs/design/specs/Ecma-335-Augments.md