Skip to content

Latest commit

 

History

History
62 lines (34 loc) · 3.77 KB

i.8.7.1-assignment-compatibility-for-signature-types.md

File metadata and controls

62 lines (34 loc) · 3.77 KB

I.8.7.1 Assignment compatibility for signature types

A signature type T is compatible-with a signature type U if and only if at least one of the following holds. [Formally, the compatible-with relation is the smallest relation that is closed under the following rules.]

  1. T is identical to U. [Note: this is reflexivity. end note]

  2. There exists some V such that T is compatible-with V and V is compatible-with U. [Note: this is transitivity. end note]

  3. T is a reference type, and U is the direct base class of T.

  4. T is a reference type, and U is an interface directly implemented by T.

  5. T is a zero-based rank-1 array V[], and U is a zero-based rank-1 array W[], and V is array-element-compatible-with W.

  6. T is an array with rank r and element type V, and U is an array with the same rank r and element type W, and V is array-element-compatible-with W.

  7. T is a zero-based rank-1 array V[], and U is IList<W>, and V is array-element-compatible-with W.

  8. T is D<T1,…,Tn> and U is D<U1,…,Un> for some interface or delegate type D with variance declarations var1 to varn, and for each i from 1 to n, one of the following holds:

    1. vari = none (no variance), and Ti is identical to Ui

    2. vari = + (covariance), and Ti is compatible-with Ui

    3. vari = - (contravariance), and Ui is compatible-with Ti

  9. T and U are method signatures and T is method-signature-compatible-with U.

A signature type T is array-element-compatible-with a signature type U if and only if T has underlying type V and U has underlying type W and either:

  1. V is compatible-with W; or

  2. V and W have the same reduced type.

[Note: in other words, array-element-compatible-with extends compatible-with but is agnostic with respect to enumerations and integral signed-ness. end note]

[Note: When W[] is compatible-with V[] and V and W have the same reduced type then no representation change from V to W shall be performed, rather the bits of the value shall be interpreted according to the type W rather than the type VIII.1.1.1). end note]

[Note: Variance rules do not mirror the reduced type equivalence rules of array-element-compatible-with. Thus, for example by rule 7 above:

IList<int16> := int16[]
IList<uint16> := int16[]

But by rule 8 above:

IList<int16> :≠ IList<uint16>

end note]

A method signature type T is method-signature-compatible-with a method signature type U if and only if:

  1. For each signature, independently, if the signature is for an instance method it carries the type of this. [Note: This is always true for the signatures of instance method pointers produced by the ldftnIII.3.41) and ldvirtftnIII.4.18) instructions. However, variables (as opposed to methods) whose signatures specified in the metadata have HASTHIS set with EXPLICITTHIS being set cannot be used in verified code and are unsupported by method-signature-compatible-with. end note]

  2. The calling conventions of T and U shall match exactly, ignoring the distinction between static and instance methods (i.e., the this parameter, if any, is not treated specially).

  3. For each parameter type of P of T, and corresponding type Q of U, P is assignable-to Q.

  4. For the return type P of T, and return type Q of U, Q is assignable-to P.