@@ -1164,8 +1164,10 @@ object Types {
11641164 /** If this type is an alias of a disjunction of stable singleton types,
11651165 * these types as a set, otherwise the empty set.
11661166 * Overridden and cached in OrType.
1167+ * @param widenOK If type proxies that are upperbounded by types with atoms
1168+ * have the same atoms.
11671169 */
1168- def atoms (implicit ctx : Context ): Set [Type ] = dealias match {
1170+ def atoms (widenOK : Boolean = false )( implicit ctx : Context ): Set [Type ] = dealias match {
11691171 case tp : SingletonType =>
11701172 def normalize (tp : Type ): Type = tp match {
11711173 case tp : SingletonType =>
@@ -1179,12 +1181,13 @@ object Types {
11791181 }
11801182 case _ => tp
11811183 }
1182- val underlyingAtoms = tp.underlying.atoms
1184+ val underlyingAtoms = tp.underlying.atoms(widenOK)
11831185 if (underlyingAtoms.isEmpty && tp.isStable) Set .empty + normalize(tp)
11841186 else underlyingAtoms
1185- case tp : ExprType => tp.resType.atoms
1186- case tp : OrType => tp.atoms // `atoms` overridden in OrType
1187- case tp : AndType => tp.tp1.atoms & tp.tp2.atoms
1187+ case tp : ExprType => tp.resType.atoms(widenOK)
1188+ case tp : OrType => tp.atoms(widenOK) // `atoms` overridden in OrType
1189+ case tp : AndType => tp.tp1.atoms(widenOK) & tp.tp2.atoms(widenOK)
1190+ case tp : TypeProxy if widenOK => tp.underlying.atoms(widenOK)
11881191 case _ => Set .empty
11891192 }
11901193
@@ -2902,22 +2905,26 @@ object Types {
29022905
29032906 private var atomsRunId : RunId = NoRunId
29042907 private var myAtoms : Set [Type ] = _
2908+ private var myWidenedAtoms : Set [Type ] = _
29052909 private var myWidened : Type = _
29062910
29072911 private def ensureAtomsComputed ()(implicit ctx : Context ): Unit =
29082912 if (atomsRunId != ctx.runId) {
2909- val atoms1 = tp1.atoms
2910- val atoms2 = tp2.atoms
2913+ val atoms1 = tp1.atoms()
2914+ val atoms2 = tp2.atoms()
29112915 myAtoms = if (atoms1.nonEmpty && atoms2.nonEmpty) atoms1 | atoms2 else Set .empty
2916+ val widenedAtoms1 = tp1.atoms(widenOK = true )
2917+ val widenedAtoms2 = tp2.atoms(widenOK = true )
2918+ myWidenedAtoms = if (widenedAtoms1.nonEmpty && widenedAtoms2.nonEmpty) widenedAtoms1 | widenedAtoms2 else Set .empty
29122919 val tp1w = tp1.widenSingletons
29132920 val tp2w = tp2.widenSingletons
29142921 myWidened = if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else tp1w | tp2w
29152922 atomsRunId = ctx.runId
29162923 }
29172924
2918- override def atoms (implicit ctx : Context ): Set [Type ] = {
2925+ override def atoms (widenOK : Boolean )( implicit ctx : Context ): Set [Type ] = {
29192926 ensureAtomsComputed()
2920- myAtoms
2927+ if widenOK then myAtoms else myWidenedAtoms
29212928 }
29222929
29232930 override def widenSingletons (implicit ctx : Context ): Type = {
0 commit comments