Skip to content

Commit 82d9b5f

Browse files
Parse 'case _' as 'Ident(_)'
1 parent 0ef4026 commit 82d9b5f

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4755,14 +4755,6 @@ object Types {
47554755
object MatchType {
47564756
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
47574757
unique(new CachedMatchType(bound, scrutinee, cases))
4758-
4759-
/** Extractor for `case _ =>` match type patterns */
4760-
object WildcardPattern {
4761-
def unapply(tp: Type)(using Context): Option[Type] = tp match {
4762-
case HKTypeLambda(LambdaParam(tl1, 0) :: Nil, defn.MatchCase(TypeParamRef(tl2, 0), bodyTp)) => Some(bodyTp)
4763-
case _ => None
4764-
}
4765-
}
47664758
}
47674759

47684760
// ------ ClassInfo, Type Bounds --------------------------------------------------

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,8 +2618,7 @@ object Parsers {
26182618
in.token match {
26192619
case USCORE if in.lookahead.isArrow =>
26202620
val start = in.skipToken()
2621-
typeBounds().withSpan(Span(start, in.lastOffset, start))
2622-
2621+
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
26232622
case _ =>
26242623
infixType()
26252624
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ class Typer extends Namer
485485
if ctx.mode.is(Mode.Pattern) then
486486
if name == nme.WILDCARD then
487487
return tree.withType(pt)
488+
if name == tpnme.WILDCARD then
489+
return tree.withType(defn.AnyType)
488490
if untpd.isVarPattern(tree) && name.isTermName then
489491
return typed(desugar.patternVar(tree), pt)
490492
else if ctx.mode.is(Mode.QuotedPattern) then
@@ -1546,13 +1548,11 @@ class Typer extends Namer
15461548
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1))
15471549
instantiateMatchTypeProto(pat1, pt) match {
15481550
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
1549-
case MatchType.WildcardPattern(_) => tpt.tpe frozen_=:= defn.AnyType
15501551
case _ => false
15511552
}
15521553
case (id @ Ident(nme.WILDCARD), pt) =>
15531554
pt match {
15541555
case defn.MatchCase(patternTp, _) => defn.AnyType frozen_=:= patternTp
1555-
case MatchType.WildcardPattern(_) => true
15561556
case _ => false
15571557
}
15581558
case _ => false
@@ -1664,7 +1664,6 @@ class Typer extends Namer
16641664
def caseRest(pat: Tree)(using Context) = {
16651665
val pt1 = instantiateMatchTypeProto(pat, pt) match {
16661666
case defn.MatchCase(_, bodyPt) => bodyPt
1667-
case MatchType.WildcardPattern(bodyPt) => bodyPt
16681667
case pt => pt
16691668
}
16701669
val pat1 = indexPattern(tree).transform(pat)

0 commit comments

Comments
 (0)