Skip to content

Commit 698f4da

Browse files
committed
address open comments.
- #1060 (comment): Take Nigel's suggestion, with minor wordsmithing. - #1060 (comment) No change in this PR. Addressed with Rex's work on Annex C. - For #1060 (comment): Use Nigel's suggestion. - For #1060 (comment): Took Nigel's suggestion. - #1060 (comment) No change. Deferred to when we address #729
1 parent 4547c98 commit 698f4da

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

standard/expressions.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7159,11 +7159,11 @@ constant_expression
71597159
;
71607160
```
71617161

7162-
A constant expression shall either have the value `null` or one of the following types:
7162+
A constant expression may be either a value type or a reference type. If a constant expression has a value type, that type shall be one of the following: `sbyte`, `byte`, `short`, `ushort`, `int`, `uint`, `nint`, `nuint`, `long`, `ulong`, `char`, `float`, `double`, `decimal`, `bool,` or any enumeration type. If a constant expression has a reference type, the expression shall:
71637163

7164-
- `sbyte`, `byte`, `short`, `ushort`, `int`, `uint`, `nint`, `nuint`, `long`, `ulong`, `char`, `float`, `double`, `decimal`, `bool`, `string`;
7165-
- an enumeration type; or
7166-
- a default value expression ([§12.8.21](expressions.md#12821-default-value-expressions)) for a reference type.
7164+
- have a value of type `string`;
7165+
- have a value of `null`; or
7166+
- be a default value expression ([§12.8.21](expressions.md#12821-default-value-expressions)) of reference type.
71677167

71687168
A *constant_expression* of type `nint` shall have a value in the range \[`int.MinValue`,`int.MaxValue`\]. A *constant_expression* of type `nuint` shall have a value in the range \[`uint.MinValue`,`uint.MaxValue`\].
71697169

@@ -7215,7 +7215,15 @@ Whenever an expression fulfills the requirements listed above, the expression is
72157215
72167216
The compile-time evaluation of constant expressions uses the same rules as run-time evaluation of non-constant expressions, except that where run-time evaluation would have thrown an exception, compile-time evaluation causes a compile-time error to occur.
72177217
7218-
Due to the implementation-defined nature of native integers ([§8.3.6](types.md#836-integral-types)), constant folding operations on `nint` and `nuint` operands shall be evaluated as if they had type `System.Int32` and `System.UInt32`, respectively. If the operation results in a constant value representable in 32 bits, constant folding may be performed at compile-time. Otherwise, the operation is executed at runtime and is not considered to be a constant.
7218+
The compile-time evaluation of a *constant_expression* shall:
7219+
7220+
- treat all values of type `nint` as `System.Int32`;
7221+
- treat all values of type `nuint` as `System.UInt32`;
7222+
- and otherwise use the same evaluation rules as for run-time non-constant expressions.
7223+
7224+
If any `nint`/`nuint` values are not representable as `Int32`/`UInt32`, or the run-time evaluation of the whole expression would throw an exception, then a compile-time error shall be produced.
7225+
7226+
> *Note*: These rules mean that an expression involving native integers which is superficially valid as a *constant_expression* may only be valid as an *expression* evaluated at runtime using the full implementation-defined native integer precision. *end note*
72197227
72207228
Unless a constant expression is explicitly placed in an `unchecked` context, overflows that occur in integral-type arithmetic operations and conversions during the compile-time evaluation of the expression always cause compile-time errors ([§12.8.20](expressions.md#12820-the-checked-and-unchecked-operators)).
72217229

standard/types.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ nullable_value_type
217217
;
218218
```
219219

220+
Because the names `nint` and `nuint` are not keywords there is syntactic ambiguity between recognising them as a *type_name* or a *value_type*. In context if type resolution (§7.8.1) on either of these names succeeds then that name shall be recognised as a *type_name*; otherwise it shall be recognised as a *value_type*.
221+
220222
Unlike a variable of a reference type, a variable of a value type can contain the value `null` only if the value type is a nullable value type ([§8.3.12](types.md#8312-nullable-value-types)). For every non-nullable value type there is a corresponding nullable value type denoting the same set of values plus the value `null`.
221223

222224
Assignment to a variable of a value type creates a *copy* of the value being assigned. This differs from assignment to a variable of a reference type, which copies the reference but not the object identified by the reference.

0 commit comments

Comments
 (0)