Skip to content

Commit a0f286b

Browse files
Parse 'case _' as 'Ident(_)'
1 parent e49fa25 commit a0f286b

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
@@ -4740,14 +4740,6 @@ object Types {
47404740
object MatchType {
47414741
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
47424742
unique(new CachedMatchType(bound, scrutinee, cases))
4743-
4744-
/** Extractor for `case _ =>` match type patterns */
4745-
object WildcardPattern {
4746-
def unapply(tp: Type)(using Context): Option[Type] = tp match {
4747-
case HKTypeLambda(LambdaParam(tl1, 0) :: Nil, defn.MatchCase(TypeParamRef(tl2, 0), bodyTp)) => Some(bodyTp)
4748-
case _ => None
4749-
}
4750-
}
47514743
}
47524744

47534745
// ------ 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
@@ -2615,8 +2615,7 @@ object Parsers {
26152615
in.token match {
26162616
case USCORE if in.lookahead.isArrow =>
26172617
val start = in.skipToken()
2618-
typeBounds().withSpan(Span(start, in.lastOffset, start))
2619-
2618+
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
26202619
case _ =>
26212620
infixType()
26222621
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ class Typer extends Namer
466466
if ctx.mode.is(Mode.Pattern) then
467467
if name == nme.WILDCARD then
468468
return tree.withType(pt)
469+
if name == tpnme.WILDCARD then
470+
return tree.withType(defn.AnyType)
469471
if untpd.isVarPattern(tree) && name.isTermName then
470472
return typed(desugar.patternVar(tree), pt)
471473
else if ctx.mode.is(Mode.QuotedPattern) then
@@ -1519,13 +1521,11 @@ class Typer extends Namer
15191521
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1))
15201522
instantiateMatchTypeProto(pat1, pt) match {
15211523
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
1522-
case MatchType.WildcardPattern(_) => tpt.tpe frozen_=:= defn.AnyType
15231524
case _ => false
15241525
}
15251526
case (id @ Ident(nme.WILDCARD), pt) =>
15261527
pt match {
15271528
case defn.MatchCase(patternTp, _) => defn.AnyType frozen_=:= patternTp
1528-
case MatchType.WildcardPattern(_) => true
15291529
case _ => false
15301530
}
15311531
case _ => false
@@ -1637,7 +1637,6 @@ class Typer extends Namer
16371637
def caseRest(pat: Tree)(using Context) = {
16381638
val pt1 = instantiateMatchTypeProto(pat, pt) match {
16391639
case defn.MatchCase(_, bodyPt) => bodyPt
1640-
case MatchType.WildcardPattern(bodyPt) => bodyPt
16411640
case pt => pt
16421641
}
16431642
val pat1 = indexPattern(tree).transform(pat)

0 commit comments

Comments
 (0)