Edit this page on GitHub

Dropped: General Type Projection

Scala 2 allowed general type projection T#A where T is an arbitrary type and A names a type member of T. This turns out to be unsound (at least when combined with other Scala 3 features).

To remedy this, Scala 3 only allows type projection if T is a concrete type (any type which is not abstract), an example for such a type would be a class type (class T). A type is abstract if it is:

  • An abstract type member (type T without = SomeType)
  • A type parameter ([T])
  • An alias to an abstract type (type T = SomeAbstractType). There are no restriction on A apart from the fact it has to be a member type of T, for example a subclass (class T { class A }).

To rewrite code using type projections on abstract types, consider using path-dependent types or implicit parameters.

This restriction rules out the type-level encoding of a combinator calculus.