@@ -423,7 +423,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
423423 (tp1.widenSingletons ne tp1) &&
424424 recur(tp1.widenSingletons, tp2)
425425
426- if (tp2.atoms.nonEmpty)
426+ if (tp2.atoms.nonEmpty && canCompare(tp2.atoms) )
427427 tp1.atoms.nonEmpty && tp1.atoms.subsetOf(tp2.atoms)
428428 else
429429 widenOK || joinOK || recur(tp11, tp2) && recur(tp12, tp2)
@@ -581,7 +581,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
581581 }
582582 compareTypeLambda
583583 case OrType (tp21, tp22) =>
584- if (tp2.atoms.nonEmpty)
584+ if (tp2.atoms.nonEmpty && canCompare(tp2.atoms) )
585585 return tp1.atoms.nonEmpty && tp1.atoms.subsetOf(tp2.atoms) ||
586586 tp1.isRef(NothingClass )
587587
@@ -1064,6 +1064,23 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
10641064 else None
10651065 }
10661066
1067+ /** Check whether we can compare the given set of atoms with another to determine
1068+ * a subtype test between OrTypes. There is one situation where this is not
1069+ * the case, which has to do with SkolemTypes. TreeChecker sometimes expects two
1070+ * types to be equal that have different skolems. To account for this, we identify
1071+ * two different skolems in all phases `p`, where `p.isTyper` is false.
1072+ * But in that case comparing two sets of atoms that contain skolems
1073+ * for equality would give the wrong result, so we should not use the sets
1074+ * for comparisons.
1075+ */
1076+ def canCompare (atoms : Set [Type ]): Boolean =
1077+ ctx.phase.isTyper || {
1078+ val hasSkolems = new ExistsAccumulator (_.isInstanceOf [SkolemType ]) {
1079+ override val stopAtStatic = true
1080+ }
1081+ ! atoms.exists(hasSkolems(false , _))
1082+ }
1083+
10671084 /** Subtype test for corresponding arguments in `args1`, `args2` according to
10681085 * variances in type parameters `tparams2`.
10691086 *
0 commit comments