@@ -1102,30 +1102,30 @@ object Types {
11021102 * Exception (if `-YexplicitNulls` is set): if this type is a nullable union (i.e. of the form `T | Null`),
11031103 * then the top-level union isn't widened. This is needed so that type inference can infer nullable types.
11041104 */
1105- def widenUnion (implicit ctx : Context ): Type = {
1106- widen match {
1107- case tp @ OrType (lhs, rhs) =>
1108- tp match {
1109- case OrNull (tp1) =>
1110- // Don't widen `T|Null`, since otherwise we wouldn't be able to infer nullable unions.
1111- val tp1Widen = tp1.widenUnion
1112- if (tp1Widen.isRef(defn. AnyClass )) tp1Widen
1113- else tp.derivedOrType(tp1Widen, defn. NullType )
1114- case _ =>
1115- ctx.typeComparer.lub(lhs.widenUnion, rhs.widenUnion, canConstrain = true ) match {
1116- case union : OrType => union.join
1117- case res => res
1118- }
1119- }
1120- case tp @ AndType (tp1, tp2) =>
1121- tp derived_& (tp1.widenUnion , tp2.widenUnion)
1122- case tp : RefinedType =>
1123- tp.derivedRefinedType(tp.parent.widenUnion, tp.refinedName, tp.refinedInfo)
1124- case tp : RecType =>
1125- tp.rebind(tp.parent.widenUnion)
1126- case tp =>
1127- tp
1128- }
1105+ def widenUnion (implicit ctx : Context ): Type = widen match {
1106+ case tp @ OrNull (tp1) : OrType =>
1107+ // Don't widen `T|Null`, since otherwise we wouldn't be able to infer nullable unions.
1108+ val tp1Widen = tp1.widenUnion
1109+ if (tp1Widen.isRef(defn. AnyClass )) tp1Widen
1110+ else tp.derivedOrType(tp1Widen, defn. NullType )
1111+ case tp =>
1112+ tp.widenUnionWithoutNull
1113+ }
1114+
1115+ def widenUnionWithoutNull ( implicit ctx : Context ) : Type = widen match {
1116+ case tp @ OrType (lhs, rhs) =>
1117+ ctx.typeComparer.lub(lhs.widenUnionWithoutNull, rhs.widenUnionWithoutNull, canConstrain = true ) match {
1118+ case union : OrType => union.join
1119+ case res => res
1120+ }
1121+ case tp @ AndType (tp1, tp2) =>
1122+ tp derived_& (tp1.widenUnionWithoutNull, tp2.widenUnionWithoutNull)
1123+ case tp : RefinedType =>
1124+ tp.derivedRefinedType(tp.parent.widenUnion, tp.refinedName, tp.refinedInfo)
1125+ case tp : RecType =>
1126+ tp.rebind(tp.parent.widenUnion)
1127+ case tp =>
1128+ tp
11291129 }
11301130
11311131 /** Widen all top-level singletons reachable by dealiasing
0 commit comments