Skip to content

Commit bb1a946

Browse files
committed
Reword reference article about type projection so that it highlights what is allowed
Was previously focused on what was forbidden/dangerous which made it feel like an unsafe feature
1 parent 3d1d012 commit bb1a946

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
---
22
layout: doc-page
3-
title: "Dropped: General Type Projection"
4-
nightlyOf: https://docs.scala-lang.org/scala3/reference/dropped-features/type-projection.html
3+
title: "Tightened Type Projection"
4+
nightlyOf: https://docs.scala-lang.org/scala3/reference/changed-features/type-projection.html
55
---
66

7-
Scala so far allowed general type projection `T#A` where `T` is an arbitrary type
8-
and `A` names a type member of `T`.
7+
Scala 2 allowed general type projection `T#A` where `T` is an arbitrary type and `A` names a type member of `T`.
8+
This turns out to be [unsound](https://github.com/scala/scala3/issues/1050) (at least when combined with other Scala 3 features).
99

10-
Scala 3 disallows this if `T` is an abstract type (class types and type aliases
11-
are fine). This change was made because unrestricted type projection
12-
is [unsound](https://github.com/scala/scala3/issues/1050).
13-
14-
This restriction rules out the [type-level encoding of a combinator
15-
calculus](https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/).
10+
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`).
11+
A type is abstract if it is:
12+
* An abstract type member (`type T` without `= SomeType`)
13+
* A type parameter (`[T]`)
14+
* An alias to an abstract type (`type T = SomeAbstactType`).
15+
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 }`).
1616

1717
To rewrite code using type projections on abstract types, consider using
1818
path-dependent types or implicit parameters.
19+
20+
This restriction rules out the [type-level encoding of a combinator
21+
calculus](https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/).

0 commit comments

Comments
 (0)