From 0b3ee5dc2ec56f8a7089980f2d2b68303844f221 Mon Sep 17 00:00:00 2001 From: jnm2 Date: Sat, 9 Aug 2025 16:28:01 -0400 Subject: [PATCH 1/3] Not every constrained type parameter may be annotated --- standard/classes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/standard/classes.md b/standard/classes.md index 2d212974c..7615f93f6 100644 --- a/standard/classes.md +++ b/standard/classes.md @@ -442,8 +442,8 @@ The nullability of the type argument need not match the nullability of the type > *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* - -The nullable type annotation, `?`, can’t be used on an unconstrained type argument. + +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*. For a type parameter `T` when the type argument is a nullable reference type `C?`, instances of `T?` are interpreted as `C?`, not `C??`. From 8a1de22f8598a182b367309174ea223b704de63c Mon Sep 17 00:00:00 2001 From: jnm2 Date: Sat, 9 Aug 2025 16:30:07 -0400 Subject: [PATCH 2/3] =?UTF-8?q?Mention=20type=20parameters=20in=20'=C2=A78?= =?UTF-8?q?.2=20Reference=20types'=20the=20same=20as=20in=20'=C2=A78.3.12?= =?UTF-8?q?=20Nullable=20value=20types'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- standard/types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/types.md b/standard/types.md index 31ccd4773..10d906541 100644 --- a/standard/types.md +++ b/standard/types.md @@ -27,7 +27,7 @@ For convenience, throughout this specification, some library type names are writ ### 8.2.1 General -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. +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. ```ANTLR reference_type From 918e022b64ebf46094be75036b8729ee89e81050 Mon Sep 17 00:00:00 2001 From: jnm2 Date: Sat, 9 Aug 2025 16:50:17 -0400 Subject: [PATCH 3/3] Remove line referring to impossible situation in C# 8 --- standard/classes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/standard/classes.md b/standard/classes.md index 7615f93f6..47dd24262 100644 --- a/standard/classes.md +++ b/standard/classes.md @@ -445,7 +445,8 @@ The nullability of the type argument need not match the nullability of the type 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*. -For a type parameter `T` when the type argument is a nullable reference type `C?`, instances of `T?` are interpreted as `C?`, not `C??`. + + > *Example*: The following examples show how the nullability of a type argument impacts the nullability of a declaration of its type parameter: >