Skip to content

Reword reference article about type projection so that it highlights what is allowed #22793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions docs/_docs/reference/dropped-features/type-projection.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ title: "Dropped: General Type Projection"
nightlyOf: https://docs.scala-lang.org/scala3/reference/dropped-features/type-projection.html
---

Scala so far allowed general type projection `T#A` where `T` is an arbitrary type
and `A` names a type member of `T`.
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](https://github.com/scala/scala3/issues/1050) (at least when combined with other Scala 3 features).

Scala 3 disallows this if `T` is an abstract type (class types and type aliases
are fine). This change was made because unrestricted type projection
is [unsound](https://github.com/scala/scala3/issues/1050).

This restriction rules out the [type-level encoding of a combinator
calculus](https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/).
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems marginal, but we can leave it in since it gives context that some people might find useful

calculus](https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/).
Loading