Section 6.1 Implicit conversions defines an identity conversion thusly:
An identity conversion converts from any type to the same type. This conversion exists such that an entity that already has a required type can be said to be convertible to that type.
Now, what is the purpose of sentences such as these?
(In §6.1.6 Implicit reference conversions)
The implicit reference conversions are:
- [...]
- From any reference-type to a reference-type
T
if it has an implicit identity or reference conversion to a reference-typeT
0 andT
0 has an identity conversion toT
.
and:
(In §6.1.7 Boxing conversions)
- A value type has a boxing conversion to an interface type
I
if it has a boxing conversion to an interface typeI
0 andI
0 has an identity conversion toI
.
Initially they seem redundant (tautologous). But they must be there for a purpose, so why are they there?
Can you give an example of two types T
1, T
2 such that T
1 would not be implicitly convertible to T
2 if it weren’t for the above-quoted paragraphs?
Section 4.7 of the specification notes that there is an identity conversion from Foo<dynamic>
to Foo<object>
and vice versa. The portion of the spec you quoted is written to ensure that this case is handled. That is, if there is an implicit reference conversion from T to C<object, object>
then there is also an implicit reference conversion to C<object, dynamic>
, C<dynamic, object>
and C<dynamic, dynamic>
.
One might reasonably point out that (1) the intention of these phrases is unobvious - hence your question - and confusing, and (2) that the section on identity conversions ought to cross-reference the section on dynamic conversions, and (3) phrases like this in the spec make it difficult for an implementor of the specification to clearly translate the spec language into an implementation. How is one to know if any such type exists? The spec need not specify exact algorithms, but it would be nice if it gave more guidance.
The spec is, sadly, not a perfect document.