Skip to content

Commit 71a227e

Browse files
Parse 'case _' as 'Ident(_)'
1 parent aa7632c commit 71a227e

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
@@ -4586,14 +4586,6 @@ object Types {
45864586
object MatchType {
45874587
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
45884588
unique(new CachedMatchType(bound, scrutinee, cases))
4589-
4590-
/** Extractor for `case _ =>` match type patterns */
4591-
object WildcardPattern {
4592-
def unapply(tp: Type)(using Context): Option[Type] = tp match {
4593-
case HKTypeLambda(LambdaParam(tl1, 0) :: Nil, defn.MatchCase(TypeParamRef(tl2, 0), bodyTp)) => Some(bodyTp)
4594-
case _ => None
4595-
}
4596-
}
45974589
}
45984590

45994591
// ------ 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
@@ -2582,7 +2582,7 @@ object Parsers {
25822582
in.token match {
25832583
case USCORE if in.lookahead.isArrow =>
25842584
val start = in.skipToken()
2585-
typeBounds().withSpan(Span(start, in.lastOffset, start))
2585+
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
25862586
case _ =>
25872587
infixType()
25882588
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ class Typer extends Namer
459459
if ctx.mode.is(Mode.Pattern) then
460460
if name == nme.WILDCARD then
461461
return tree.withType(pt)
462+
if name == tpnme.WILDCARD then
463+
return tree.withType(defn.AnyType)
462464
if untpd.isVarPattern(tree) && name.isTermName then
463465
return typed(desugar.patternVar(tree), pt)
464466
else if ctx.mode.is(Mode.QuotedPattern) then
@@ -1482,13 +1484,11 @@ class Typer extends Namer
14821484
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1))
14831485
instantiateMatchTypeProto(pat1, pt) match {
14841486
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
1485-
case MatchType.WildcardPattern(_) => tpt.tpe frozen_=:= defn.AnyType
14861487
case _ => false
14871488
}
14881489
case (id @ Ident(nme.WILDCARD), pt) =>
14891490
pt match {
14901491
case defn.MatchCase(patternTp, _) => defn.AnyType frozen_=:= patternTp
1491-
case MatchType.WildcardPattern(_) => true
14921492
case _ => false
14931493
}
14941494
case _ => false
@@ -1600,7 +1600,6 @@ class Typer extends Namer
16001600
def caseRest(pat: Tree)(using Context) = {
16011601
val pt1 = instantiateMatchTypeProto(pat, pt) match {
16021602
case defn.MatchCase(_, bodyPt) => bodyPt
1603-
case MatchType.WildcardPattern(bodyPt) => bodyPt
16041603
case pt => pt
16051604
}
16061605
val pat1 = indexPattern(tree).transform(pat)

0 commit comments

Comments
 (0)