Skip to content

Commit 2e22b1c

Browse files
Parse 'case _' as 'Ident(_)'
1 parent b17c259 commit 2e22b1c

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
@@ -4650,14 +4650,6 @@ object Types {
46504650
object MatchType {
46514651
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
46524652
unique(new CachedMatchType(bound, scrutinee, cases))
4653-
4654-
/** Extractor for `case _ =>` match type patterns */
4655-
object WildcardPattern {
4656-
def unapply(tp: Type)(using Context): Option[Type] = tp match {
4657-
case HKTypeLambda(LambdaParam(tl1, 0) :: Nil, defn.MatchCase(TypeParamRef(tl2, 0), bodyTp)) => Some(bodyTp)
4658-
case _ => None
4659-
}
4660-
}
46614653
}
46624654

46634655
// ------ 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
@@ -2613,7 +2613,7 @@ object Parsers {
26132613
in.token match {
26142614
case USCORE if in.lookahead.isArrow =>
26152615
val start = in.skipToken()
2616-
typeBounds().withSpan(Span(start, in.lastOffset, start))
2616+
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
26172617
case _ =>
26182618
infixType()
26192619
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ class Typer extends Namer
462462
if ctx.mode.is(Mode.Pattern) then
463463
if name == nme.WILDCARD then
464464
return tree.withType(pt)
465+
if name == tpnme.WILDCARD then
466+
return tree.withType(defn.AnyType)
465467
if untpd.isVarPattern(tree) && name.isTermName then
466468
return typed(desugar.patternVar(tree), pt)
467469
else if ctx.mode.is(Mode.QuotedPattern) then
@@ -1503,13 +1505,11 @@ class Typer extends Namer
15031505
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1))
15041506
instantiateMatchTypeProto(pat1, pt) match {
15051507
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
1506-
case MatchType.WildcardPattern(_) => tpt.tpe frozen_=:= defn.AnyType
15071508
case _ => false
15081509
}
15091510
case (id @ Ident(nme.WILDCARD), pt) =>
15101511
pt match {
15111512
case defn.MatchCase(patternTp, _) => defn.AnyType frozen_=:= patternTp
1512-
case MatchType.WildcardPattern(_) => true
15131513
case _ => false
15141514
}
15151515
case _ => false
@@ -1621,7 +1621,6 @@ class Typer extends Namer
16211621
def caseRest(pat: Tree)(using Context) = {
16221622
val pt1 = instantiateMatchTypeProto(pat, pt) match {
16231623
case defn.MatchCase(_, bodyPt) => bodyPt
1624-
case MatchType.WildcardPattern(bodyPt) => bodyPt
16251624
case pt => pt
16261625
}
16271626
val pat1 = indexPattern(tree).transform(pat)

0 commit comments

Comments
 (0)