Skip to content

Commit b402193

Browse files
Parse 'case _' as 'Ident(_)'
1 parent e848c97 commit b402193

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4735,14 +4735,6 @@ object Types {
47354735
object MatchType {
47364736
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
47374737
unique(new CachedMatchType(bound, scrutinee, cases))
4738-
4739-
/** Extractor for `case _ =>` match type patterns */
4740-
object WildcardPattern {
4741-
def unapply(tp: Type)(using Context): Option[Type] = tp match {
4742-
case HKTypeLambda(LambdaParam(tl1, 0) :: Nil, defn.MatchCase(TypeParamRef(tl2, 0), bodyTp)) => Some(bodyTp)
4743-
case _ => None
4744-
}
4745-
}
47464738
}
47474739

47484740
// ------ ClassInfo, Type Bounds --------------------------------------------------

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,7 @@ object Parsers {
26142614
in.token match {
26152615
case USCORE if in.lookahead.isArrow =>
26162616
val start = in.skipToken()
2617-
typeBounds().withSpan(Span(start, in.lastOffset, start))
2617+
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
26182618
case _ =>
26192619
infixType()
26202620
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ class Typer extends Namer
465465
if ctx.mode.is(Mode.Pattern) then
466466
if name == nme.WILDCARD then
467467
return tree.withType(pt)
468+
if name == tpnme.WILDCARD then
469+
return tree.withType(defn.AnyType)
468470
if untpd.isVarPattern(tree) && name.isTermName then
469471
return typed(desugar.patternVar(tree), pt)
470472
else if ctx.mode.is(Mode.QuotedPattern) then
@@ -1518,13 +1520,11 @@ class Typer extends Namer
15181520
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1))
15191521
instantiateMatchTypeProto(pat1, pt) match {
15201522
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
1521-
case MatchType.WildcardPattern(_) => tpt.tpe frozen_=:= defn.AnyType
15221523
case _ => false
15231524
}
15241525
case (id @ Ident(nme.WILDCARD), pt) =>
15251526
pt match {
15261527
case defn.MatchCase(patternTp, _) => defn.AnyType frozen_=:= patternTp
1527-
case MatchType.WildcardPattern(_) => true
15281528
case _ => false
15291529
}
15301530
case _ => false
@@ -1636,7 +1636,6 @@ class Typer extends Namer
16361636
def caseRest(pat: Tree)(using Context) = {
16371637
val pt1 = instantiateMatchTypeProto(pat, pt) match {
16381638
case defn.MatchCase(_, bodyPt) => bodyPt
1639-
case MatchType.WildcardPattern(bodyPt) => bodyPt
16401639
case pt => pt
16411640
}
16421641
val pat1 = indexPattern(tree).transform(pat)

0 commit comments

Comments
 (0)