Skip to content

Commit 9128823

Browse files
committed
add comment
1 parent f03eade commit 9128823

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
@@ -607,11 +607,13 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
607607
if (tref.symbol.is(Module)) mapOver(tref)
608608
else newTypeVar(TypeBounds.upper(tp.underlying))
609609
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
610-
// See tests/patmat/3645b.scala
610+
// Note that the logic for contra- and co-variance is reverse of `typeParamMap`
611+
// This is because we are checking the possibility of `tp1 <:< tp2`, thus we should
612+
// minimize `tp1` while maximize `tp2`. See tests/patmat/3645b.scala
611613
val exposed =
612614
if (variance == 0) newTypeVar(tp.underlying.bounds)
613-
else if (variance == 1) mapOver(tp.underlying.hiBound)
614-
else mapOver(tp.underlying.loBound)
615+
else if (variance == 1) mapOver(tp.underlying.loBound)
616+
else mapOver(tp.underlying.hiBound)
615617

616618
debug.println(s"$tp exposed to =====> $exposed")
617619
exposed
@@ -653,7 +655,11 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
653655
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
654656
val protoTp1 = thisTypeMap(tp1.appliedTo(tvars))
655657

656-
// tests/patmat/3645b.scala
658+
// If parent contains a reference to an abstract type, then we should
659+
// refine subtype checking to eliminate abstract types according to
660+
// variance. As this logic is only needed in exhaustivity check, thus
661+
// we manually patch subtyping check instead of changing TypeComparer.
662+
// See tests/patmat/3645b.scala
657663
def parentQualify = tp1.widen.classSymbol.info.parents.exists { parent =>
658664
(parent.argInfos.nonEmpty || parent.abstractTypeMembers.nonEmpty) &&
659665
instantiate(parent, tp2)(ctx.fresh.setNewTyperState()).exists

0 commit comments

Comments
 (0)