Skip to content

Commit

Permalink
Always interpret underscores inside patterns as type bounds (#21718)
Browse files Browse the repository at this point in the history
Always interpret underscores inside patterns as type bounds, even when
`ctx.settings.XkindProjector.value == "underscores"`.

Fixes #14952 and fixes #21400.

Issue introduced in #12378.
  • Loading branch information
smarter authored Oct 7, 2024
2 parents 588e0b9 + 374cd4f commit 6c7619a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1988,7 +1988,7 @@ object Parsers {
if isSimpleLiteral then
SingletonTypeTree(simpleLiteral())
else if in.token == USCORE then
if ctx.settings.XkindProjector.value == "underscores" then
if ctx.settings.XkindProjector.value == "underscores" && !inMatchPattern then
val start = in.skipToken()
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
else
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/14952.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//> using options -Xkind-projector:underscores

import Tuple.*

type LiftP[F[_], T] <: Tuple =
T match {
case _ *: _ => F[Head[T]] *: LiftP[F, Tail[T]]
case _ => EmptyTuple
}
7 changes: 7 additions & 0 deletions tests/pos/21400.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//> using options -Xkind-projector:underscores

import scala.compiletime.ops.int.S

type IndexOf[T <: Tuple, E] <: Int = T match
case E *: _ => 0
case _ *: es => 1 // S[IndexOf[es, E]]
10 changes: 10 additions & 0 deletions tests/pos/21400b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//> using options -Xkind-projector:underscores

import scala.quoted.Type
import scala.quoted.Quotes

def x[A](t: Type[A])(using Quotes): Boolean = t match
case '[_ *: _] =>
true
case _ =>
false

0 comments on commit 6c7619a

Please sign in to comment.