Skip to content

Commit 9d6f8cc

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 0d5234a commit 9d6f8cc

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
@@ -7027,11 +7027,11 @@ constant_expression
70277027
;
70287028
```
70297029

7030-
A constant expression shall either have the value `null` or one of the following types:
7030+
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:
70317031

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

70367036
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`\].
70377037

@@ -7083,7 +7083,15 @@ Whenever an expression fulfills the requirements listed above, the expression is
70837083
70847084
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.
70857085
7086-
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.
7086+
The compile-time evaluation of a *constant_expression* shall:
7087+
7088+
- treat all values of type `nint` as `System.Int32`;
7089+
- treat all values of type `nuint` as `System.UInt32`;
7090+
- and otherwise use the same evaluation rules as for run-time non-constant expressions.
7091+
7092+
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.
7093+
7094+
> *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*
70877095
70887096
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)).
70897097

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)