Skip to content

Are transparent extension types in a subtype relation with their on type? #1464

Closed
@leafpetersen

Description

@leafpetersen

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 of E
  • Make O be equivalent to E (i.e. treat it as a typedef in the equational theory)
  • Make O be assignable to E (that is, treat it as if there were an implicit coercion from O to E)

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions