Skip to content

Commit 4c23197

Browse files
Parse 'case _' as 'Ident(_)'
1 parent 9c29d78 commit 4c23197

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
@@ -4734,14 +4734,6 @@ object Types {
47344734
object MatchType {
47354735
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
47364736
unique(new CachedMatchType(bound, scrutinee, cases))
4737-
4738-
/** Extractor for `case _ =>` match type patterns */
4739-
object WildcardPattern {
4740-
def unapply(tp: Type)(using Context): Option[Type] = tp match {
4741-
case HKTypeLambda(LambdaParam(tl1, 0) :: Nil, defn.MatchCase(TypeParamRef(tl2, 0), bodyTp)) => Some(bodyTp)
4742-
case _ => None
4743-
}
4744-
}
47454737
}
47464738

47474739
// ------ 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
@@ -2615,7 +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))
2618+
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
26192619
case _ =>
26202620
infixType()
26212621
}

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)