Skip to content

Commit fe7eb74

Browse files
Parse 'case _' as 'Ident(_)'
1 parent 314c190 commit fe7eb74

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
@@ -4630,14 +4630,6 @@ object Types {
46304630
object MatchType {
46314631
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
46324632
unique(new CachedMatchType(bound, scrutinee, cases))
4633-
4634-
/** Extractor for `case _ =>` match type patterns */
4635-
object WildcardPattern {
4636-
def unapply(tp: Type)(using Context): Option[Type] = tp match {
4637-
case HKTypeLambda(LambdaParam(tl1, 0) :: Nil, defn.MatchCase(TypeParamRef(tl2, 0), bodyTp)) => Some(bodyTp)
4638-
case _ => None
4639-
}
4640-
}
46414633
}
46424634

46434635
// ------ 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
@@ -2602,7 +2602,7 @@ object Parsers {
26022602
in.token match {
26032603
case USCORE if in.lookahead.isArrow =>
26042604
val start = in.skipToken()
2605-
typeBounds().withSpan(Span(start, in.lastOffset, start))
2605+
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
26062606
case _ =>
26072607
infixType()
26082608
}

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
@@ -1499,13 +1501,11 @@ class Typer extends Namer
14991501
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1))
15001502
instantiateMatchTypeProto(pat1, pt) match {
15011503
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
1502-
case MatchType.WildcardPattern(_) => tpt.tpe frozen_=:= defn.AnyType
15031504
case _ => false
15041505
}
15051506
case (id @ Ident(nme.WILDCARD), pt) =>
15061507
pt match {
15071508
case defn.MatchCase(patternTp, _) => defn.AnyType frozen_=:= patternTp
1508-
case MatchType.WildcardPattern(_) => true
15091509
case _ => false
15101510
}
15111511
case _ => false
@@ -1617,7 +1617,6 @@ class Typer extends Namer
16171617
def caseRest(pat: Tree)(using Context) = {
16181618
val pt1 = instantiateMatchTypeProto(pat, pt) match {
16191619
case defn.MatchCase(_, bodyPt) => bodyPt
1620-
case MatchType.WildcardPattern(bodyPt) => bodyPt
16211620
case pt => pt
16221621
}
16231622
val pat1 = indexPattern(tree).transform(pat)

0 commit comments

Comments
 (0)