Skip to content

Commit 5e21fa7

Browse files
committed
Remove redundant (and incomplete) description of array element checking
This already existed in the right place (in the list of argument evaluation steps) but the example was associated with the duplicate. Fixes dotnet#801.
1 parent ee25423 commit 5e21fa7

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

standard/expressions.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,29 @@ During the run-time processing of a function member invocation ([§12.6.6](expre
619619
>
620620
> *end example*
621621
622-
- For an input, output, or reference argument, the variable reference is evaluated and the resulting storage location becomes the storage location represented by the parameter in the function member invocation. For an input or reference argument, the variable shall be definitely assigned at the point of the method call. If the variable reference given as an output, or reference is an array element of a *reference_type*, a run-time check is performed to ensure that the element type of the array is identical to the type of the parameter. If this check fails, a `System.ArrayTypeMismatchException` is thrown.
622+
- For an input, output, or reference argument, the variable reference is evaluated and the resulting storage location becomes the storage location represented by the parameter in the function member invocation. For an input or reference argument, the variable shall be definitely assigned at the point of the method call. If the variable reference given as an output, or the variable reference is an array element of a *reference_type*, a run-time check is performed to ensure that the element type of the array is identical to the type of the parameter. If this check fails, a `System.ArrayTypeMismatchException` is thrown. *Note*: this run-time check is required due to array covariance ([§17.6](arrays.md#176-array-covariance)). *end note*
623+
624+
> *Example*: In the following code
625+
>
626+
> <!-- Example: {template:"standalone-console-without-using", name:"Run-timeEvalOfArgLists2", replaceEllipsis:true, expectedException:"ArrayTypeMismatchException"} -->
627+
> ```csharp
628+
> class Test
629+
> {
630+
> static void F(ref object x) {...}
631+
>
632+
> static void Main()
633+
> {
634+
> object[] a = new object[10];
635+
> object[] b = new string[10];
636+
> F(ref a[0]); // Ok
637+
> F(ref b[1]); // ArrayTypeMismatchException
638+
> }
639+
> }
640+
> ```
641+
>
642+
> the second invocation of `F` causes a `System.ArrayTypeMismatchException` to be thrown because the actual element type of `b` is `string` and not `object`.
643+
>
644+
> *end example*
623645
624646
Methods, indexers, and instance constructors may declare their right-most parameter to be a parameter array ([§15.6.2.6](classes.md#15626-parameter-arrays)). Such function members are invoked either in their normal form or in their expanded form depending on which is applicable ([§12.6.4.2](expressions.md#12642-applicable-function-member)):
625647
@@ -655,30 +677,6 @@ The expressions of an argument list are always evaluated in textual order.
655677
>
656678
> *end example*
657679
658-
The array co-variance rules ([§17.6](arrays.md#176-array-covariance)) permit a value of an array type `A[]` to be a reference to an instance of an array type `B[]`, provided an implicit reference conversion exists from `B` to `A`. Because of these rules, when an array element of a *reference_type* is passed as an output or reference argument, a run-time check is required to ensure that the actual element type of the array is *identical* to that of the parameter.
659-
660-
> *Example*: In the following code
661-
>
662-
> <!-- Example: {template:"standalone-console-without-using", name:"Run-timeEvalOfArgLists2", replaceEllipsis:true, expectedException:"ArrayTypeMismatchException"} -->
663-
> ```csharp
664-
> class Test
665-
> {
666-
> static void F(ref object x) {...}
667-
>
668-
> static void Main()
669-
> {
670-
> object[] a = new object[10];
671-
> object[] b = new string[10];
672-
> F(ref a[0]); // Ok
673-
> F(ref b[1]); // ArrayTypeMismatchException
674-
> }
675-
> }
676-
> ```
677-
>
678-
> the second invocation of `F` causes a `System.ArrayTypeMismatchException` to be thrown because the actual element type of `b` is `string` and not `object`.
679-
>
680-
> *end example*
681-
682680
When a function member with a parameter array is invoked in its expanded form with at least one expanded argument, the invocation is processed as if an array creation expression with an array initializer ([§12.8.16.5](expressions.md#128165-array-creation-expressions)) was inserted around the expanded arguments. An empty array is passed when there are no arguments for the parameter array; it is unspecified whether the reference passed is to a newly allocated or existing empty array.
683681
684682
> *Example*: Given the declaration

0 commit comments

Comments
 (0)