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
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions docs/_docs/reference/changed-features/type-projection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
layout: doc-page
title: "Tightened Type Projection"
nightlyOf: https://docs.scala-lang.org/scala3/reference/changed-features/type-projection.html
---

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).

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 = SomeAbstactType`).
There are no restriction on `A` appart 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](https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/).
18 changes: 0 additions & 18 deletions docs/_docs/reference/dropped-features/type-projection.md

This file was deleted.

Loading