Skip to content
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

Always interpret underscores inside patterns as type bounds #21718

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading