Skip to content

Commit 374cd4f

Browse files
committed
Always treat underscores as type bounds inside patterns
Always treat underscores as type bounds inside patterns, even when `ctx.settings.XkindProjector.value == "underscores"`. Fixes scala#14952 and scala#21400.
1 parent 588e0b9 commit 374cd4f

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ object Parsers {
19881988
if isSimpleLiteral then
19891989
SingletonTypeTree(simpleLiteral())
19901990
else if in.token == USCORE then
1991-
if ctx.settings.XkindProjector.value == "underscores" then
1991+
if ctx.settings.XkindProjector.value == "underscores" && !inMatchPattern then
19921992
val start = in.skipToken()
19931993
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
19941994
else

Diff for: tests/pos/14952.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using options -Xkind-projector:underscores
2+
3+
import Tuple.*
4+
5+
type LiftP[F[_], T] <: Tuple =
6+
T match {
7+
case _ *: _ => F[Head[T]] *: LiftP[F, Tail[T]]
8+
case _ => EmptyTuple
9+
}

Diff for: tests/pos/21400.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//> using options -Xkind-projector:underscores
2+
3+
import scala.compiletime.ops.int.S
4+
5+
type IndexOf[T <: Tuple, E] <: Int = T match
6+
case E *: _ => 0
7+
case _ *: es => 1 // S[IndexOf[es, E]]

Diff for: tests/pos/21400b.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//> using options -Xkind-projector:underscores
2+
3+
import scala.quoted.Type
4+
import scala.quoted.Quotes
5+
6+
def x[A](t: Type[A])(using Quotes): Boolean = t match
7+
case '[_ *: _] =>
8+
true
9+
case _ =>
10+
false

0 commit comments

Comments
 (0)