From e7f088e4891b9a06d376d8d2e2af4017abc35632 Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Thu, 13 Mar 2025 12:39:46 +0100 Subject: [PATCH 1/6] 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename docs/_docs/reference/{dropped-features => changed-features}/type-projection.md (92%) diff --git a/docs/_docs/reference/dropped-features/type-projection.md b/docs/_docs/reference/changed-features/type-projection.md similarity index 92% rename from docs/_docs/reference/dropped-features/type-projection.md rename to docs/_docs/reference/changed-features/type-projection.md index 08b5ffb34eca..2c3e82ce99b8 100644 --- a/docs/_docs/reference/dropped-features/type-projection.md +++ b/docs/_docs/reference/changed-features/type-projection.md @@ -9,7 +9,7 @@ and `A` names a type member of `T`. 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/lampepfl/dotty/issues/1050). +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/). From c18c223c9684e027218285bfc0d1022401081e34 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Sat, 26 Apr 2025 11:00:40 +0200 Subject: [PATCH 2/6] Move type-projection file This commit only exists to avoid git being confused, it is not independent of the following commit ! [Cherry-picked 3d1d012c2191f24e77290aebae587deaa3fdf91d][modified] From 0ef884eefec2c05465818396b9455a48e7868d07 Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Thu, 13 Mar 2025 13:03:20 +0100 Subject: [PATCH 3/6] 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 [Cherry-picked bb1a94634074a7c1d8a2704ea353fc946b50d58c] --- .../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 c61d0b4fe3a2945287f5ea7e5dbd6f8730777bba Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Sat, 15 Mar 2025 18:04:17 +0100 Subject: [PATCH 4/6] Re-move type-projection [Cherry-picked f963f17a9fa5c11a8ba22c12c31506858bb5832a] --- .../{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 99117640a96541b74e2f264edcdaaa7a54d4753f Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Sat, 15 Mar 2025 18:07:59 +0100 Subject: [PATCH 5/6] De-rename the page [Cherry-picked 126fc253fd22a089c3e8d109f4a3e4958d02310c] --- 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 671e601beaf938ab3bd2dec2a50c295034c615d3 Mon Sep 17 00:00:00 2001 From: Quentin Bernet Date: Sat, 15 Mar 2025 18:08:10 +0100 Subject: [PATCH 6/6] Fix typo [Cherry-picked a9830ea1334195cb433cece929215dafa92d6857] --- 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.