Skip to content

Commit 586d0d1

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 755c835 commit 586d0d1

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
@@ -7206,10 +7206,9 @@ constant_expression
72067206
;
72077207
```
72087208

7209-
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:
7209+
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:
72107210

7211-
- have a value of type `string`;
7212-
- have a value of `null`; or
7211+
- have a value of type `string`; or
72137212
- be a default value expression ([§12.8.21](expressions.md#12821-default-value-expressions)) of reference type.
72147213

72157214
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)