Support ? as wildcard marker under -Xsource:3#9560
Merged
SethTisue merged 1 commit intoscala:2.13.xfrom Apr 8, 2021
Merged
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.
Member
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) 😕 |
smarter
added a commit
to smarter/kind-projector
that referenced
this pull request
Apr 30, 2021
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.
neko-kai
added a commit
to 7mind/kind-projector
that referenced
this pull request
May 7, 2021
…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 } ```
neko-kai
added a commit
to 7mind/kind-projector
that referenced
this pull request
May 7, 2021
…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 } ```
smarter
added a commit
to smarter/scala
that referenced
this pull request
May 10, 2021
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.
smarter
added a commit
to smarter/scala
that referenced
this pull request
May 10, 2021
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.
smarter
added a commit
to smarter/scala
that referenced
this pull request
May 10, 2021
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.
lrytz
pushed a commit
to smarter/scala
that referenced
this pull request
May 11, 2021
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.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.