Skip to content

Commit

Permalink
[create-pull-request] automated change (#1216)
Browse files Browse the repository at this point in the history
Co-authored-by: BillWagner <[email protected]>
  • Loading branch information
github-actions[bot] and BillWagner authored Nov 20, 2024
1 parent a7525ff commit 2f5f317
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
8 changes: 4 additions & 4 deletions standard/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,12 @@ The class type, reference type constraint, and secondary constraints can include
- If the constraint does not include the nullable type annotation, the type argument is expected to be a non-nullable reference type. A compiler may issue a warning if the type argument is a nullable reference type.
- If the constraint includes the nullable type annotation, the constraint is satisfied by both a non-nullable reference type and a nullable reference type.

The nullability of the type argument need not match the nullability of the type parameter. The compiler may issue a warning if the nullability of the type parameter doesn't match the nullability of the type argument.
The nullability of the type argument need not match the nullability of the type parameter. The compiler may issue a warning if the nullability of the type parameter doesnt match the nullability of the type argument.

> *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*
> *Note*: To specify that a type argument is a nullable reference type, dont 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*
<!-- Remove in C# 9, when this is allowed -->
The nullable type annotation, `?`, can't be used on an unconstrained type argument.
The nullable type annotation, `?`, cant be used on an unconstrained type argument.

For a type parameter `T` when the type argument is a nullable reference type `C?`, instances of `T?` are interpreted as `C?`, not `C??`.

Expand Down Expand Up @@ -491,7 +491,7 @@ For a type parameter `T` when the type argument is a nullable reference type `C?
>
> *end example*
The ***not null*** constraint specifies that a type argument used for the type parameter should be a non-nullable value type or a non-nullable reference type. A type argument that isn't a non-nullable value type or a non-nullable reference type is allowed, but the compiler may produce a diagnostic warning.
The ***not null*** constraint specifies that a type argument used for the type parameter should be a non-nullable value type or a non-nullable reference type. A type argument that isnt a non-nullable value type or a non-nullable reference type is allowed, but the compiler may produce a diagnostic warning.
The value type constraint specifies that a type argument used for the type parameter shall be a non-nullable value type. All non-nullable struct types, enum types, and type parameters having the value type constraint satisfy this constraint. Note that although classified as a value type, a nullable value type ([§8.3.12](types.md#8312-nullable-value-types)) does not satisfy the value type constraint. A type parameter having the value type constraint shall not also have the *constructor_constraint*, although it may be used as a type argument for another type parameter with a *constructor_constraint*.
Expand Down
35 changes: 20 additions & 15 deletions standard/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,14 @@ delegate_type
;
nullable_reference_type
: non_nullable_reference_type '?'
: non_nullable_reference_type nullable_type_annotation
;
nullable_type_annotation
: '?'
;
// Source: §8.3.1 General
value_type
: non_nullable_value_type
Expand Down Expand Up @@ -692,7 +697,7 @@ enum_type
;
nullable_value_type
: non_nullable_value_type '?'
: non_nullable_value_type nullable_type_annotation
;
// Source: §8.4.2 Type arguments
Expand All @@ -706,6 +711,7 @@ type_arguments
type_argument
: type
| type_parameter nullable_type_annotation?
;
// Source: §8.5 Type parameters
Expand Down Expand Up @@ -1966,33 +1972,32 @@ type_parameter_constraints_clauses
: type_parameter_constraints_clause
| type_parameter_constraints_clauses type_parameter_constraints_clause
;
type_parameter_constraints_clause
: 'where' type_parameter ':' type_parameter_constraints
;
type_parameter_constraints
: primary_constraint
| secondary_constraints
: primary_constraint (',' secondary_constraints)? (',' constructor_constraint)?
| secondary_constraints (',' constructor_constraint)?
| constructor_constraint
| primary_constraint ',' secondary_constraints
| primary_constraint ',' constructor_constraint
| secondary_constraints ',' constructor_constraint
| primary_constraint ',' secondary_constraints ',' constructor_constraint
;
primary_constraint
: class_type
| 'class'
: class_type nullable_type_annotation?
| 'class' nullable_type_annotation?
| 'struct'
| 'notnull'
| 'unmanaged'
;
secondary_constraint
: interface_type nullable_type_annotation?
| type_parameter nullable_type_annotation?
;
secondary_constraints
: interface_type
| type_parameter
| secondary_constraints ',' interface_type
| secondary_constraints ',' type_parameter
: secondary_constraint (',' secondary_constraint)*
;
constructor_constraint
Expand Down
2 changes: 1 addition & 1 deletion standard/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ When the nullable context is ***enabled***:
- For any reference type `T`, the annotation `?` in `T?` makes `T?` a nullable type, whereas the unannotated `T` is non-nullable.
- The compiler can use static flow analysis to determine the null state of any reference variable. When nullable warnings are enabled, a reference variables null state ([§8.9.5](types.md#895-nullabilities-and-null-states)) is either *not null*, *maybe null*, or *maybe default* and
- The null-forgiving operator `!` ([§12.8.9](expressions.md#1289-null-forgiving-expressions)) sets the null state of its operand to *not null*.
- The compiler can issue a warning if the nullability of a type parameter doesn't match the nullability of its corresponding type argument.
- The compiler can issue a warning if the nullability of a type parameter doesnt match the nullability of its corresponding type argument.
### 8.9.5 Nullabilities and null states
Expand Down

0 comments on commit 2f5f317

Please sign in to comment.