Skip to content

Commit aa5e4b5

Browse files
committed
Document the exception to the rule that nullable annotations can be ignored by compilers
1 parent 066fbfc commit aa5e4b5

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

standard/types.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,25 @@ There are two forms of nullability for reference types:
729729

730730
> *Note:* The types `R` and `R?` are represented by the same underlying type, `R`. A variable of that underlying type can either contain a reference to an object or be the value `null`, which indicates “no reference.” *end note*
731731
732-
The syntactic distinction between a *nullable reference type* and its corresponding *non-nullable reference type* enables a compiler to generate diagnostics. A compiler must allow the *nullable_type_annotation* as defined in [§8.2.1](types.md#821-general). The diagnostics must be limited to warnings. Neither the presence or absence of nullable annotations, nor the state of the nullable context can change the compile time or runtime behavior of a program except for changes in any diagnostic messages generated at compile time.
732+
The syntactic distinction between a *nullable reference type* and its corresponding *non-nullable reference type* enables a compiler to generate diagnostics. A compiler must allow the *nullable_type_annotation* as defined in [§8.2.1](types.md#821-general). The diagnostics must be limited to warnings. Neither the presence or absence of nullable annotations, nor the state of the nullable context can change the compile time or runtime behavior of a program except for changes in any diagnostic messages generated at compile time, with one exception:
733+
734+
A compiler must respect the effect that *nullable_type_annotation* has on the ordering of array rank specifiers. Whereas `A[][,]` is a single *array_type* with two *rank_specifier*s, the presence of a nullable annotation between the rank specifiers in `A[]?[,]` causes it to no longer be a single *array_type*, but rather two: an outer *array_type* with a single *rank_specifier* of `[,]`, and an element type of `A[]?` which is a *nullable_reference_type* containing an inner *array_type* with a single *rank_specifier* of `[]`. Because of this, `A[]?[,]` and `A[,][]` are represented by the same underlying type, while `A[]?[,]` and `A[][,]` are not.
735+
736+
> *Example*: The array ranks are interrupted by the '?' in the parameter type, changing the meaning of the underlying array type:
737+
>
738+
> <!-- Example: {template:"code-in-class-lib", name:"ArraysOfNullAbleArrays"} -->
739+
> ```csharp
740+
> #nullable enable
741+
> class C
742+
> {
743+
> void M(string[][,]?[,,][,,,] arrays)
744+
> {
745+
> string? value = arrays[3, 3, 3][4, 4, 4, 4]?[1][2, 2];
746+
> }
747+
> }
748+
> ```
749+
>
750+
> *end example*
733751
734752
### 8.9.2 Non-nullable reference types
735753

0 commit comments

Comments
 (0)