Closed
Description
The initial extension type proposal from @eernstg suggests that an extension type is a supertype of its on type.
Ignoring the question of whether transparent extension types by default are the right choice for now (that is, whether implicit assignment into the type is what we want), there is a question of whether doing so via subtyping is the right choice. There are at least three alternatives, given an extension E
with on type O
:
- Make
O
be a proper subtype ofE
- Make
O
be equivalent toE
(i.e. treat it as a typedef in the equational theory) - Make
O
be assignable toE
(that is, treat it as if there were an implicit coercion fromO
toE
)
Examples:
extension class E on int {}
E e = 3; // Valid if `E` is a supertype of `int`, or if `E` is equivalent to `int`, or if `int` is assignable to `E`
int i = e; // Valid only if `E` is equivalent to `int`
List<E> x = <int>[]; // Valid only if `E` is a supertype of `int`
Ignoring the technical issues around handling the subtyping which I will file a separate issue for, what are the arguments for using subtyping vs assignability vs equivalence?