Skip to content

Commit 858e32b

Browse files
committed
Use * as a placeholder in addition to ?.
Motivation: There is a proposal for F[?] to denote a wildcard (currently F[_]) in Scala 3.0+ and F[_] to be a shorthand syntax for type lambda (F[?] with current kind-projector syntax) in Scala 3.3+ (see scala/scala3#5379). Supporting an additional placeholder will allow users to gradually move from `?` to `*` before Scala 3.0 is out. Resolves typelevel#84.
1 parent 1c8f595 commit 858e32b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/main/scala/KindProjector.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,24 @@ class KindRewriter(plugin: Plugin, val global: Global)
5151
// Reserve some names
5252
val TypeLambda1 = newTypeName("Lambda")
5353
val TypeLambda2 = newTypeName("λ")
54-
val InvPlaceholder = newTypeName("$qmark")
55-
val CoPlaceholder = newTypeName("$plus$qmark")
56-
val ContraPlaceholder = newTypeName("$minus$qmark")
54+
object InvPlaceholder {
55+
def unapply(name: TypeName): Boolean = name == newTypeName("$qmark") || name == newTypeName("$times")
56+
}
57+
object CoPlaceholder {
58+
def unapply(name: TypeName): Boolean = name == newTypeName("$plus$qmark") || name == newTypeName("$plus$times")
59+
}
60+
object ContraPlaceholder {
61+
def unapply(name: TypeName): Boolean = name == newTypeName("$minus$qmark") || name == newTypeName("$minus$times")
62+
}
5763

5864
val TermLambda1 = TypeLambda1.toTermName
5965
val TermLambda2 = TypeLambda2.toTermName
6066

6167
object Placeholder {
6268
def unapply(name: TypeName): Option[Variance] = name match {
63-
case InvPlaceholder => Some(Invariant)
64-
case CoPlaceholder => Some(Covariant)
65-
case ContraPlaceholder => Some(Contravariant)
69+
case InvPlaceholder() => Some(Invariant)
70+
case CoPlaceholder() => Some(Covariant)
71+
case ContraPlaceholder() => Some(Contravariant)
6672
case _ => None
6773
}
6874
}

src/test/scala/test.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ object Test {
1616
// used to test the plugin
1717
bar[Either[Int, ?]]
1818
baz[Tuple3[Int, ?, ?]]
19+
baz[Tuple3[*, Int, *]]
1920

2021
// should not be changed by the plugin
2122
foo[Either[Int, Double]]
@@ -42,6 +43,7 @@ object Test {
4243
trait EitherT[F[_], A, B]
4344
qux[Functor[?[_]]]
4445
qux[EitherT[?[_], Int, Double]]
46+
qux[EitherT[*[_], Int, Double]]
4547

4648
// higher higher order
4749
def vex[T[_[_[_]]]] = ()
@@ -69,6 +71,7 @@ object Test {
6971
def bux[T[-_, +_]] = ()
7072
bux[({type L[-A, +B] = Function2[A, Int, B]})#L]
7173
bux[Function2[-?, Int, +?]]
74+
bux[Function2[-*, Int, +*]]
7275
bux[Lambda[(`-A`, `+B`) => Function2[A, Int, B]]]
7376
bux[Lambda[(-[A], +[B]) => Function2[A, Int, B]]]
7477

@@ -77,7 +80,9 @@ object Test {
7780
def tux[T[-F[_]]] = ()
7881
def hux[T[+G[_]]] = ()
7982
tux[~>[-?[_], Option]]
83+
tux[~>[-*[_], Option]]
8084
hux[~>[Option, +?[_]]]
85+
hux[~>[Option, +*[_]]]
8186
tux[Lambda[`-F[_]` => ~>[F, Option]]]
8287
hux[Lambda[`+G[_]` => ~>[Option, G]]]
8388
}

0 commit comments

Comments
 (0)