Skip to content

Commit e012a07

Browse files
BillWagnerjskeet
authored andcommitted
Item 15: §12.17 Fix null coalescing operator condition
Replace "an unmanaged type (§8.8) or known to be a non-nullable value type" with "a non-nullable value type or a pointer type in unsafe code"
1 parent ed50882 commit e012a07

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

standard/expressions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5051,7 +5051,7 @@ The null coalescing operator is right-associative, meaning that operations are g
50515051
50525052
The type of the expression `a ?? b` depends on which implicit conversions are available on the operands. In order of preference, the type of `a ?? b` is `A₀`, `A`, or `B`, where `A` is the type of `a` (provided that `a` has a type), `B` is the type of `b`(provided that `b` has a type), and `A₀` is the underlying type of `A` if `A` is a nullable value type, or `A` otherwise. Specifically, `a ?? b` is processed as follows:
50535053

5054-
- If `A` exists and is an unmanaged type ([§8.8](types.md#88-unmanaged-types)) or known to be a non-nullable value type, a compile-time error occurs.
5054+
- If `A` exists and is a non-nullable value type or a pointer type in unsafe code, a compile-time error occurs.
50555055
- Otherwise, if `A` exists and `b` is a dynamic expression, the result type is `dynamic`. At run-time, `a` is first evaluated. If `a` is not `null`, `a` is converted to `dynamic`, and this becomes the result. Otherwise, `b` is evaluated, and this becomes the result.
50565056
- Otherwise, if `A` exists and is a nullable value type and an implicit conversion exists from `b` to `A₀`, the result type is `A₀`. At run-time, `a` is first evaluated. If `a` is not `null`, `a` is unwrapped to type `A₀`, and this becomes the result. Otherwise, `b` is evaluated and converted to type `A₀`, and this becomes the result.
50575057
- Otherwise, if `A` exists and an implicit conversion exists from `b` to `A`, the result type is `A`. At run-time, `a` is first evaluated. If `a` is not `null`, `a` becomes the result. Otherwise, `b` is evaluated and converted to type `A`, and this becomes the result.

0 commit comments

Comments
 (0)