Skip to content

Commit a68184a

Browse files
committed
Constant expression fix
Changed from "A constant expression may be either a value type or a reference type" (with null only under the reference type branch) to "A constant expression shall have the value null, or be of a value type or a reference type." This hoists null to the top level so it's valid regardless of target type — covering nullable value type defaults like void M(int? x = null). Removed the now-redundant null bullet from the reference type list.
1 parent a0fe4b7 commit a68184a

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

standard/expressions.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7193,10 +7193,9 @@ constant_expression
71937193
;
71947194
```
71957195

7196-
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:
7196+
A constant expression shall have the value `null`, or be of 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:
71977197

7198-
- have a value of type `string`;
7199-
- have a value of `null`; or
7198+
- have a value of type `string`; or
72007199
- be a default value expression ([§12.8.21](expressions.md#12821-default-value-expressions)) of reference type.
72017200

72027201
A *constant_expression* of type `nint` shall have a value in the range \[-2147483648, 2147483647\]. A *constant_expression* of type `nuint` shall have a value in the range \[0, 4294967295\].

0 commit comments

Comments
 (0)