Skip to content

Commit f20da6b

Browse files
committed
add comment
1 parent 727b29d commit f20da6b

File tree

1 file changed

+10
-4
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,13 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
588588
if (tref.symbol.is(Module)) mapOver(tref)
589589
else newTypeVar(TypeBounds.upper(tp.underlying))
590590
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
591-
// See tests/patmat/3645b.scala
591+
// Note that the logic for contra- and co-variance is reverse of `typeParamMap`
592+
// This is because we are checking the possibility of `tp1 <:< tp2`, thus we should
593+
// minimize `tp1` while maximize `tp2`. See tests/patmat/3645b.scala
592594
val exposed =
593595
if (variance == 0) newTypeVar(tp.underlying.bounds)
594-
else if (variance == 1) mapOver(tp.underlying.hiBound)
595-
else mapOver(tp.underlying.loBound)
596+
else if (variance == 1) mapOver(tp.underlying.loBound)
597+
else mapOver(tp.underlying.hiBound)
596598

597599
debug.println(s"$tp exposed to =====> $exposed")
598600
exposed
@@ -634,7 +636,11 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
634636
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
635637
val protoTp1 = thisTypeMap(tp1.appliedTo(tvars))
636638

637-
// tests/patmat/3645b.scala
639+
// If parent contains a reference to an abstract type, then we should
640+
// refine subtype checking to eliminate abstract types according to
641+
// variance. As this logic is only needed in exhaustivity check, thus
642+
// we manually patch subtyping check instead of changing TypeComparer.
643+
// See tests/patmat/3645b.scala
638644
def parentQualify = tp1.widen.classSymbol.info.parents.exists { parent =>
639645
(parent.argInfos.nonEmpty || parent.abstractTypeMembers.nonEmpty) &&
640646
instantiate(parent, tp2)(ctx.fresh.setNewTyperState()).exists

0 commit comments

Comments
 (0)