From 3d1d012c2191f24e77290aebae587deaa3fdf91d Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Thu, 13 Mar 2025 12:39:46 +0100 Subject: [PATCH 1/5] Move type-projection file This commit only exists to avoid git being confused, it is not independent of the following commit ! --- .../{dropped-features => changed-features}/type-projection.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/_docs/reference/{dropped-features => changed-features}/type-projection.md (100%) diff --git a/docs/_docs/reference/dropped-features/type-projection.md b/docs/_docs/reference/changed-features/type-projection.md similarity index 100% rename from docs/_docs/reference/dropped-features/type-projection.md rename to docs/_docs/reference/changed-features/type-projection.md From bb1a94634074a7c1d8a2704ea353fc946b50d58c Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Thu, 13 Mar 2025 13:03:20 +0100 Subject: [PATCH 2/5] 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 --- .../changed-features/type-projection.md | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/_docs/reference/changed-features/type-projection.md b/docs/_docs/reference/changed-features/type-projection.md index 2c3e82ce99b8..32c56029ce51 100644 --- a/docs/_docs/reference/changed-features/type-projection.md +++ b/docs/_docs/reference/changed-features/type-projection.md @@ -1,18 +1,21 @@ --- layout: doc-page -title: "Dropped: General Type Projection" -nightlyOf: https://docs.scala-lang.org/scala3/reference/dropped-features/type-projection.html +title: "Tightened Type Projection" +nightlyOf: https://docs.scala-lang.org/scala3/reference/changed-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 = 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/). \ No newline at end of file From f963f17a9fa5c11a8ba22c12c31506858bb5832a Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Sat, 15 Mar 2025 18:04:17 +0100 Subject: [PATCH 3/5] Re-move type-projection --- .../{changed-features => dropped-features}/type-projection.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/_docs/reference/{changed-features => dropped-features}/type-projection.md (100%) diff --git a/docs/_docs/reference/changed-features/type-projection.md b/docs/_docs/reference/dropped-features/type-projection.md similarity index 100% rename from docs/_docs/reference/changed-features/type-projection.md rename to docs/_docs/reference/dropped-features/type-projection.md From 126fc253fd22a089c3e8d109f4a3e4958d02310c Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Sat, 15 Mar 2025 18:07:59 +0100 Subject: [PATCH 4/5] De-rename the page --- docs/_docs/reference/dropped-features/type-projection.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/_docs/reference/dropped-features/type-projection.md b/docs/_docs/reference/dropped-features/type-projection.md index 32c56029ce51..3dbba9d9fa89 100644 --- a/docs/_docs/reference/dropped-features/type-projection.md +++ b/docs/_docs/reference/dropped-features/type-projection.md @@ -1,7 +1,7 @@ --- layout: doc-page -title: "Tightened Type Projection" -nightlyOf: https://docs.scala-lang.org/scala3/reference/changed-features/type-projection.html +title: "Dropped: General Type Projection" +nightlyOf: https://docs.scala-lang.org/scala3/reference/dropped-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`. From a9830ea1334195cb433cece929215dafa92d6857 Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Sat, 15 Mar 2025 18:08:10 +0100 Subject: [PATCH 5/5] Fix typo --- docs/_docs/reference/dropped-features/type-projection.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/_docs/reference/dropped-features/type-projection.md b/docs/_docs/reference/dropped-features/type-projection.md index 3dbba9d9fa89..9b9f643ceb6e 100644 --- a/docs/_docs/reference/dropped-features/type-projection.md +++ b/docs/_docs/reference/dropped-features/type-projection.md @@ -11,8 +11,8 @@ To remedy this, Scala 3 only allows type projection if `T` is a concrete type (a 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 }`). +* 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.