Skip to content

Commit b79db0e

Browse files
authored
Merge pull request #1389 from dotnet/jnm2/nrt_type_params
Fix small spec bugs regarding nullable reference type parameters
2 parents 8d07381 + 918e022 commit b79db0e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

standard/classes.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,11 @@ The nullability of the type argument need not match the nullability of the type
442442

443443
> *Note*: To specify that a type argument is a nullable reference type, don’t add the nullable type annotation as a constraint (use `T : class` or `T : BaseClass`), but use `T?` throughout the generic declaration to indicate the corresponding nullable reference type for the type argument. *end note*
444444
445-
<!-- Remove in C# 9, when this is allowed -->
446-
The nullable type annotation, `?`, can’t be used on an unconstrained type argument.
445+
<!-- Remove in C# 9, when `?` is allowed on any type parameter. -->
446+
The nullable type annotation, `?`, can only be used on a type parameter that has the value type constraint, the reference type constraint without the *nullable_type_annotation*, or a class type constraint without the *nullable_type_annotation*.
447447

448-
For a type parameter `T` when the type argument is a nullable reference type `C?`, instances of `T?` are interpreted as `C?`, not `C??`.
448+
<!-- Add in C# 9, when `?` is allowed on nullable reference type parameters. -->
449+
<!-- For a type parameter `T` when the type argument is a nullable reference type `C?`, instances of `T?` are interpreted as `C?`, not `C??`. -->
449450

450451
> *Example*: The following examples show how the nullability of a type argument impacts the nullability of a declaration of its type parameter:
451452
>

standard/types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ For convenience, throughout this specification, some library type names are writ
2727

2828
### 8.2.1 General
2929

30-
A reference type is a class type, an interface type, an array type, a delegate type, or the `dynamic` type. For each non-nullable reference type, there is a corresponding nullable reference type noted by appending the `?` to the type name.
30+
A reference type is a class type, an interface type, an array type, a delegate type, the `dynamic` type, or any type parameter that is constrained to be a reference type (that is, any type parameter with the reference type constraint or a class type constraint ([§15.2.5](classes.md#1525-type-parameter-constraints))). For each non-nullable reference type, there is a corresponding nullable reference type noted by appending the `?` to the type name.
3131

3232
```ANTLR
3333
reference_type

0 commit comments

Comments
 (0)