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
Support ?
as wildcard marker under -Xsource:3
#9560
Conversation
Like in Scala 3.0, this allows `?` to be used as a type argument in all situations where `_` could be used as a wildcard previously. This should allow us to deprecate the use of `_` as a wildcard in Scala 3 to be able to eventually repurpose it as explained in http://dotty.epfl.ch/docs/reference/changed-features/wildcards.html This is a source-breaking change since a type named `?` is legal in Scala 2 (but not in Scala 3 unless -source 3.0-migration is used). `?` also has a special meaning when the kind-projector plugin is used, but that usage has been deprecated in favor of `*` for a while now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
Unfortunately it looks like it was deprecated in the docs since Sep 2019 (typelevel/kind-projector#109) but only emits a deprecation warnings since the end of November 2020 (i.e. https://github.com/typelevel/kind-projector/releases/tag/v0.11.2) 😕 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Scala 2.13.6 and 2.12.14 will interpret `?` as a wildcard when using the `-Xsource:3` flag (cf scala/scala#9560)). This means that the old kind-projector syntax will no longer work, so it seems like a good time to remove it. This will also allow us to compile more of the community-build with `-Xsource:3` enabled (cf scala/scala-dev#769). Sincet this is a breaking change, we also bump the version to 0.12.0-SNAPSHOT.
…ymous type lambdas The syntax roughly follows the [proposed new syntax for wildcards and placeholders](https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html#migration-strategy) for Scala 3.2+ and is designed to allow cross-compilation of libraries between Scala 2 and Scala 3 while using the new Scala 3 syntax for both versions. To enable this mode, add `-P:kind-projector:underscore-placeholders` to your scalac command-line. In sbt you may do this as follows: ```scala ThisBuild / scalacOptions += "-P:kind-projector:underscore-placeholders" ``` This mode is designed to be used with scalac versions `2.12.14`+ and `2.13.6`+, these versions add an the ability to use `?` as the existential type wildcard ([scala/scala#9560](scala/scala#9560)), allowing to repurpose the underscore without losing the ability to write existential types. It is not advised that you use this mode with older versions of scalac or without `-Xsource:3` flag, since you will lose the underscore syntax entirely. Here are a few examples: ```scala Tuple2[_, Double] // equivalent to: type R[A] = Tuple2[A, Double] Either[Int, +_] // equivalent to: type R[+A] = Either[Int, A] Function2[-_, Long, +_] // equivalent to: type R[-A, +B] = Function2[A, Long, B] EitherT[_[_], Int, _] // equivalent to: type R[F[_], B] = EitherT[F, Int, B] ``` Examples with `-Xsource:3`'s `?`-wildcard: ```scala Tuple2[_, ?] // equivalent to: type R[A] = Tuple2[A, x] forSome { type x } Either[?, +_] // equivalent to: type R[+A] = Either[x, A] forSome { type x } Function2[-_, ?, +_] // equivalent to: type R[-A, +B] = Function2[A, x, B] forSome { type x } EitherT[_[_], ?, _] // equivalent to: type R[F[_], B] = EitherT[F, x, B] forSome { type x } ```
…ymous type lambdas The syntax roughly follows the [proposed new syntax for wildcards and placeholders](https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html#migration-strategy) for Scala 3.2+ and is designed to allow cross-compilation of libraries between Scala 2 and Scala 3 while using the new Scala 3 syntax for both versions. To enable this mode, add `-P:kind-projector:underscore-placeholders` to your scalac command-line. In sbt you may do this as follows: ```scala ThisBuild / scalacOptions += "-P:kind-projector:underscore-placeholders" ``` This mode is designed to be used with scalac versions `2.12.14`+ and `2.13.6`+, these versions add an the ability to use `?` as the existential type wildcard ([scala/scala#9560](scala/scala#9560)), allowing to repurpose the underscore without losing the ability to write existential types. It is not advised that you use this mode with older versions of scalac or without `-Xsource:3` flag, since you will lose the underscore syntax entirely. Here are a few examples: ```scala Tuple2[_, Double] // equivalent to: type R[A] = Tuple2[A, Double] Either[Int, +_] // equivalent to: type R[+A] = Either[Int, A] Function2[-_, Long, +_] // equivalent to: type R[-A, +B] = Function2[A, Long, B] EitherT[_[_], Int, _] // equivalent to: type R[F[_], B] = EitherT[F, Int, B] ``` Examples with `-Xsource:3`'s `?`-wildcard: ```scala Tuple2[_, ?] // equivalent to: type R[A] = Tuple2[A, x] forSome { type x } Either[?, +_] // equivalent to: type R[+A] = Either[x, A] forSome { type x } Function2[-_, ?, +_] // equivalent to: type R[-A, +B] = Function2[A, x, B] forSome { type x } EitherT[_[_], ?, _] // equivalent to: type R[F[_], B] = EitherT[F, x, B] forSome { type x } ```
scala#9560 introduced a new meaning for `?` under `-Xsource:3`, but to smooth out the migration it'd be nice if we could also enable this meaning by default. Before doing so, let's deprecate any current usage of `?` as a type that isn't wrapped in backticks.
scala#9560 introduced a new meaning for `?` under `-Xsource:3`, but to smooth out the migration it'd be nice if we could also enable this meaning by default. Before doing so, let's deprecate any current usage of `?` as a type that isn't wrapped in backticks.
scala#9560 introduced a new meaning for `?` under `-Xsource:3`, but to smooth out the migration it'd be nice if we could also enable this meaning by default. Before doing so, let's deprecate any current usage of `?` as a type that isn't wrapped in backticks.
scala#9560 introduced a new meaning for `?` under `-Xsource:3`, but to smooth out the migration it'd be nice if we could also enable this meaning by default. Before doing so, let's deprecate any current usage of `?` as a type that isn't wrapped in backticks.
Like in Scala 3.0, this allows
?
to be used as a type argument in allsituations where
_
could be used as a wildcard previously. This shouldallow us to deprecate the use of
_
as a wildcard in Scala 3 to be ableto eventually repurpose it as explained in
http://dotty.epfl.ch/docs/reference/changed-features/wildcards.html
This is a source-breaking change since a type named
?
is legal inScala 2 (but not in Scala 3 unless -source 3.0-migration is used).
?
also has a special meaning when the kind-projector plugin is used,but that usage has been deprecated in favor of
*
for a while now.