@@ -1156,8 +1156,10 @@ object Types {
1156
1156
/** If this type is an alias of a disjunction of stable singleton types,
1157
1157
* these types as a set, otherwise the empty set.
1158
1158
* Overridden and cached in OrType.
1159
+ * @param widenOK If type proxies that are upperbounded by types with atoms
1160
+ * have the same atoms.
1159
1161
*/
1160
- def atoms (implicit ctx : Context ): Set [Type ] = dealias match {
1162
+ def atoms (widenOK : Boolean = false )( implicit ctx : Context ): Set [Type ] = dealias match {
1161
1163
case tp : SingletonType =>
1162
1164
def normalize (tp : Type ): Type = tp match {
1163
1165
case tp : SingletonType =>
@@ -1171,12 +1173,13 @@ object Types {
1171
1173
}
1172
1174
case _ => tp
1173
1175
}
1174
- val underlyingAtoms = tp.underlying.atoms
1176
+ val underlyingAtoms = tp.underlying.atoms(widenOK)
1175
1177
if (underlyingAtoms.isEmpty && tp.isStable) Set .empty + normalize(tp)
1176
1178
else underlyingAtoms
1177
- case tp : ExprType => tp.resType.atoms
1178
- case tp : OrType => tp.atoms // `atoms` overridden in OrType
1179
- case tp : AndType => tp.tp1.atoms & tp.tp2.atoms
1179
+ case tp : ExprType => tp.resType.atoms(widenOK)
1180
+ case tp : OrType => tp.atoms(widenOK) // `atoms` overridden in OrType
1181
+ case tp : AndType => tp.tp1.atoms(widenOK) & tp.tp2.atoms(widenOK)
1182
+ case tp : TypeProxy if widenOK => tp.underlying.atoms(widenOK)
1180
1183
case _ => Set .empty
1181
1184
}
1182
1185
@@ -2894,22 +2897,26 @@ object Types {
2894
2897
2895
2898
private var atomsRunId : RunId = NoRunId
2896
2899
private var myAtoms : Set [Type ] = _
2900
+ private var myWidenedAtoms : Set [Type ] = _
2897
2901
private var myWidened : Type = _
2898
2902
2899
2903
private def ensureAtomsComputed ()(implicit ctx : Context ): Unit =
2900
2904
if (atomsRunId != ctx.runId) {
2901
- val atoms1 = tp1.atoms
2902
- val atoms2 = tp2.atoms
2905
+ val atoms1 = tp1.atoms()
2906
+ val atoms2 = tp2.atoms()
2903
2907
myAtoms = if (atoms1.nonEmpty && atoms2.nonEmpty) atoms1 | atoms2 else Set .empty
2908
+ val widenedAtoms1 = tp1.atoms(widenOK = true )
2909
+ val widenedAtoms2 = tp2.atoms(widenOK = true )
2910
+ myWidenedAtoms = if (widenedAtoms1.nonEmpty && widenedAtoms2.nonEmpty) widenedAtoms1 | widenedAtoms2 else Set .empty
2904
2911
val tp1w = tp1.widenSingletons
2905
2912
val tp2w = tp2.widenSingletons
2906
2913
myWidened = if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else tp1w | tp2w
2907
2914
atomsRunId = ctx.runId
2908
2915
}
2909
2916
2910
- override def atoms (implicit ctx : Context ): Set [Type ] = {
2917
+ override def atoms (widenOK : Boolean )( implicit ctx : Context ): Set [Type ] = {
2911
2918
ensureAtomsComputed()
2912
- myAtoms
2919
+ if widenOK then myAtoms else myWidenedAtoms
2913
2920
}
2914
2921
2915
2922
override def widenSingletons (implicit ctx : Context ): Type = {
0 commit comments