Skip to content

Commit

Permalink
Parse 'case _' as 'Ident(_)'
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierBlanvillain committed May 27, 2021
1 parent aa7632c commit 71a227e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
8 changes: 0 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4586,14 +4586,6 @@ object Types {
object MatchType {
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
unique(new CachedMatchType(bound, scrutinee, cases))

/** Extractor for `case _ =>` match type patterns */
object WildcardPattern {
def unapply(tp: Type)(using Context): Option[Type] = tp match {
case HKTypeLambda(LambdaParam(tl1, 0) :: Nil, defn.MatchCase(TypeParamRef(tl2, 0), bodyTp)) => Some(bodyTp)
case _ => None
}
}
}

// ------ ClassInfo, Type Bounds --------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2582,7 +2582,7 @@ object Parsers {
in.token match {
case USCORE if in.lookahead.isArrow =>
val start = in.skipToken()
typeBounds().withSpan(Span(start, in.lastOffset, start))
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
case _ =>
infixType()
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ class Typer extends Namer
if ctx.mode.is(Mode.Pattern) then
if name == nme.WILDCARD then
return tree.withType(pt)
if name == tpnme.WILDCARD then
return tree.withType(defn.AnyType)
if untpd.isVarPattern(tree) && name.isTermName then
return typed(desugar.patternVar(tree), pt)
else if ctx.mode.is(Mode.QuotedPattern) then
Expand Down Expand Up @@ -1482,13 +1484,11 @@ class Typer extends Namer
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1))
instantiateMatchTypeProto(pat1, pt) match {
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
case MatchType.WildcardPattern(_) => tpt.tpe frozen_=:= defn.AnyType
case _ => false
}
case (id @ Ident(nme.WILDCARD), pt) =>
pt match {
case defn.MatchCase(patternTp, _) => defn.AnyType frozen_=:= patternTp
case MatchType.WildcardPattern(_) => true
case _ => false
}
case _ => false
Expand Down Expand Up @@ -1600,7 +1600,6 @@ class Typer extends Namer
def caseRest(pat: Tree)(using Context) = {
val pt1 = instantiateMatchTypeProto(pat, pt) match {
case defn.MatchCase(_, bodyPt) => bodyPt
case MatchType.WildcardPattern(bodyPt) => bodyPt
case pt => pt
}
val pat1 = indexPattern(tree).transform(pat)
Expand Down

0 comments on commit 71a227e

Please sign in to comment.