You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reword reference article about type projection so that it highlights what is allowed (#22793)
Was previously focused on what was forbidden/dangerous which made it
feel like an unsafe feature
See for example:
https://users.scala-lang.org/t/path-dependent-types-accessing-outer-class/10620/8
I left the paragraph about "type-level encoding of a combinator
calculus" but it feels more like trivia than useful information ?
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).
9
9
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
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 = SomeAbstractType`).
15
+
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 }`).
16
16
17
17
To rewrite code using type projections on abstract types, consider using
18
18
path-dependent types or implicit parameters.
19
+
20
+
This restriction rules out the [type-level encoding of a combinator
0 commit comments