Skip to content

Commit cd5a1d1

Browse files
committed
address review
1 parent 179f4d9 commit cd5a1d1

File tree

1 file changed

+9
-11
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+9
-11
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -710,29 +710,26 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
710710

711711
/** Whether the counterexample is satisfiable. The space is flattened and non-empty. */
712712
def satisfiable(sp: Space): Boolean = {
713+
def impossible: Nothing = throw new AssertionError("`satisfiable` only accepts flattened space.")
714+
713715
def genConstraint(space: Space): List[(Type, Type)] = space match {
714716
case Prod(tp, unappTp, unappSym, ss, _) =>
715717
val tps = signature(unappTp, unappSym, ss.length)
716718
ss.zip(tps).flatMap {
717719
case (sp : Prod, tp) => sp.tp -> tp :: genConstraint(sp)
718720
case (Typ(tp1, _), tp2) => tp1 -> tp2 :: Nil
719-
case _ => ??? // impossible
721+
case _ => impossible
720722
}
721723
case Typ(_, _) => Nil
722-
case _ => ??? // impossible
724+
case _ => impossible
723725
}
724726

725727
def checkConstraint(constrs: List[(Type, Type)])(implicit ctx: Context): Boolean = {
726728
val tvarMap = collection.mutable.Map.empty[Symbol, TypeVar]
727729
val typeParamMap = new TypeMap() {
728730
override def apply(tp: Type): Type = tp match {
729731
case tref: TypeRef if tref.symbol.is(TypeParam) =>
730-
if (tvarMap.contains(tref.symbol)) tvarMap(tref.symbol)
731-
else {
732-
val tvar = newTypeVar(tref.underlying.bounds)
733-
tvarMap(tref.symbol) = tvar
734-
tvar
735-
}
732+
tvarMap.getOrElseUpdate(tref.symbol, newTypeVar(tref.underlying.bounds))
736733
case tp => mapOver(tp)
737734
}
738735
}
@@ -810,10 +807,11 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
810807
res
811808
}
812809

813-
def checkGADT(tp: Type): Boolean = {
810+
/** Whehter counter-examples should be further checked? True for GADTs. */
811+
def shouldCheckExamples(tp: Type): Boolean = {
814812
new TypeAccumulator[Boolean] {
815813
override def apply(b: Boolean, tp: Type): Boolean = tp match {
816-
case tref: TypeRef if tref.symbol.is(TypeParam) && variance == 0 => true
814+
case tref: TypeRef if tref.symbol.is(TypeParam) && variance != 1 => true
817815
case tp => b || foldOver(b, tp)
818816
}
819817
}.apply(false, tp)
@@ -830,7 +828,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
830828
space
831829
}).reduce((a, b) => Or(List(a, b)))
832830

833-
val checkGADTSAT = checkGADT(selTyp)
831+
val checkGADTSAT = shouldCheckExamples(selTyp)
834832

835833
val uncovered =
836834
flatten(simplify(minus(Typ(selTyp, true), patternSpace), aggressive = true))

0 commit comments

Comments
 (0)