Skip to content

Commit db5b36e

Browse files
RexJaeschkeBillWagner
authored andcommitted
Update classes.md
1 parent 3563471 commit db5b36e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

standard/classes.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ primary_constraint
434434
| 'struct'
435435
| 'notnull'
436436
| 'unmanaged'
437+
| 'default'
437438
;
438439
439440
secondary_constraint
@@ -454,7 +455,9 @@ Each *type_parameter_constraints_clause* consists of the token `where`, followed
454455

455456
The list of constraints given in a `where` clause can include any of the following components, in this order: a single primary constraint, one or more secondary constraints, and the constructor constraint, `new()`.
456457

457-
A primary constraint can be a class type, the ***reference type constraint*** `class`, the ***value type constraint*** `struct`, the ***not null constraint*** `notnull` or the ***unmanaged type constraint*** `unmanaged`. The class type and the reference type constraint can include the *nullable_type_annotation*.
458+
A primary constraint can be a class type, the ***reference type constraint*** `class`, the ***value type constraint*** `struct`, the ***not null constraint*** `notnull`, the ***unmanaged type constraint*** `unmanaged`, or `default`. The class type and the reference type constraint can include the *nullable_type_annotation*.
459+
460+
It is a compile-time error to use a `default` constraint other than on a method override or explicit implementation. It is a compile-time error to use a `default` constraint when the corresponding type parameter in the overridden or interface method is constrained to a reference type or value type.
458461

459462
A secondary constraint can be an *interface_type* or *type_parameter*, optionally followed by a *nullable_type_annotation*. The presence of the *nullable_type_annotation* indicates that the type argument is allowed to be the nullable reference type that corresponds to a non-nullable reference type that satisfies the constraint.
460463

@@ -559,6 +562,8 @@ The unmanaged type constraint specifies that a type argument used for the type p
559562
560563
Because `unmanaged` is not a keyword, in *primary_constraint* the unmanaged constraint is always syntactically ambiguous with *class_type*. For compatibility reasons, if a name lookup ([§12.8.4](expressions.md#1284-simple-names)) of the name `unmanaged` succeeds it is treated as a `class_type`. Otherwise it is treated as the unmanaged constraint.
561564
565+
The `default` constraint allows a *nullable_type_annotation* on a type parameter that is not constrained to reference types or value types.
566+
562567
Pointer types are never allowed to be type arguments, and dont satisfy any type constraints, even unmanaged, despite being unmanaged types.
563568
564569
If a constraint is a class type, an interface type, or a type parameter, that type specifies a minimal “base type” that every type argument used for that type parameter shall support. Whenever a constructed type or generic method is used, the type argument is checked against the constraints on the type parameter at compile-time. The type argument supplied shall satisfy the conditions described in [§8.4.5](types.md#845-satisfying-constraints).

0 commit comments

Comments
 (0)