Skip to content

Commit ccd2a45

Browse files
committed
Erase pattern bound variables
1 parent 10230b8 commit ccd2a45

File tree

1 file changed

+30
-8
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+30
-8
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,25 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
351351
Typ(c.value.asInstanceOf[Symbol].termRef, false)
352352
else
353353
Typ(ConstantType(c), false)
354-
case pat: Ident if isBackquoted(pat) => Typ(pat.tpe, false)
354+
355+
case pat: Ident if isBackquoted(pat) =>
356+
Typ(pat.tpe, false)
357+
355358
case Ident(nme.WILDCARD) =>
356-
Or(Typ(pat.tpe.stripAnnots, false) :: constantNullSpace :: Nil)
359+
Or(Typ(erase(pat.tpe.stripAnnots), false) :: constantNullSpace :: Nil)
360+
357361
case Ident(_) | Select(_, _) =>
358362
Typ(erase(pat.tpe.stripAnnots), false)
359-
case Alternative(trees) => Or(trees.map(project(_)))
360-
case Bind(_, pat) => project(pat)
361-
case SeqLiteral(pats, _) => projectSeq(pats)
363+
364+
case Alternative(trees) =>
365+
Or(trees.map(project(_)))
366+
367+
case Bind(_, pat) =>
368+
project(pat)
369+
370+
case SeqLiteral(pats, _) =>
371+
projectSeq(pats)
372+
362373
case UnApply(fun, _, pats) =>
363374
val (fun1, _, _) = decomposeCall(fun)
364375
val funRef = fun1.tpe.asInstanceOf[TermRef]
@@ -374,15 +385,22 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
374385
}
375386
else
376387
Prod(erase(pat.tpe.stripAnnots), funRef, pats.map(project), isIrrefutableUnapply(fun, pats.length))
377-
case Typed(pat @ UnApply(_, _, _), _) => project(pat)
388+
389+
case Typed(pat @ UnApply(_, _, _), _) =>
390+
project(pat)
391+
378392
case Typed(expr, _) =>
379393
Typ(erase(expr.tpe.stripAnnots), true)
394+
380395
case This(_) =>
381396
Typ(pat.tpe.stripAnnots, false)
397+
382398
case EmptyTree => // default rethrow clause of try/catch, check tests/patmat/try2.scala
383399
Typ(WildcardType, false)
400+
384401
case Block(Nil, expr) =>
385402
project(expr)
403+
386404
case _ =>
387405
// Pattern is an arbitrary expression; assume a skolem (i.e. an unknown value) of the pattern type
388406
Typ(pat.tpe.narrow, false)
@@ -490,6 +508,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
490508
val unappSym = unapp.symbol
491509
def caseClass = unappSym.owner.linkedClass
492510

511+
// println("scrutineeTp = " + scrutineeTp.show)
512+
493513
lazy val caseAccessors = caseClass.caseAccessors.filter(_.is(Method))
494514

495515
def isSyntheticScala2Unapply(sym: Symbol) =
@@ -503,6 +523,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
503523
val mt = pt.instantiate(tvars).asInstanceOf[MethodType]
504524
scrutineeTp <:< mt.paramInfos(0)
505525
instantiateSelected(mt, tvars)
526+
// isFullyDefined(mt, ForceDegree.flipBottom)
527+
// println("mt = " + mt.show)
506528
mt
507529
}
508530
}
@@ -648,7 +670,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
648670
case _ => tp.show
649671
}
650672

651-
def refine(tp: Type): String = tp.stripAnnots match {
673+
def refine(tp: Type): String = tp.stripAnnots.stripTypeVar match {
652674
case tp: RefinedType => refine(tp.parent)
653675
case tp: AppliedType =>
654676
refine(tp.typeConstructor) + (
@@ -744,7 +766,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
744766
val sym = fun.symbol
745767
val isUnapplySeq = sym.name.eq(nme.unapplySeq)
746768
val paramsStr = params.map(doShow(_, flattenList = isUnapplySeq)).mkString("(", ", ", ")")
747-
showType(sym.owner.typeRef) + paramsStr
769+
showType(fun.prefix) + paramsStr
748770
}
749771
case Or(_) =>
750772
throw new Exception("incorrect flatten result " + s)

0 commit comments

Comments
 (0)