@@ -239,7 +239,11 @@ object Types {
239239 case tp : AndType =>
240240 loop(tp.tp1) || loop(tp.tp2)
241241 case tp : OrType =>
242- loop(tp.tp1) && loop(tp.tp2)
242+ // If the type is `T | Null` or `T | Nothing`, and `T` derivesFrom the class,
243+ // then the OrType derivesFrom the class. Otherwise, we need to check both sides
244+ // derivesFrom the class.
245+ if defn.isBottomType(tp.tp1) then loop(tp.tp2)
246+ else loop(tp.tp1) && (defn.isBottomType(tp.tp2) || loop(tp.tp2))
243247 case tp : JavaArrayType =>
244248 cls == defn.ObjectClass
245249 case _ =>
@@ -262,7 +266,7 @@ object Types {
262266 }
263267
264268 /** Is this type exactly Nothing (no vars, aliases, refinements etc allowed)? */
265- def isBottomType (using Context ): Boolean = this match {
269+ def isNothingType (using Context ): Boolean = this match {
266270 case tp : TypeRef =>
267271 tp.name == tpnme.Nothing && (tp.symbol eq defn.NothingClass )
268272 case _ => false
@@ -2122,7 +2126,7 @@ object Types {
21222126 case arg : TypeBounds =>
21232127 val v = param.paramVarianceSign
21242128 val pbounds = param.paramInfo
2125- if (v > 0 && pbounds.loBound.dealiasKeepAnnots.isBottomType ) TypeAlias (arg.hiBound & rebase(pbounds.hiBound))
2129+ if (v > 0 && pbounds.loBound.dealiasKeepAnnots.isNothingType ) TypeAlias (arg.hiBound & rebase(pbounds.hiBound))
21262130 else if (v < 0 && pbounds.hiBound.dealiasKeepAnnots.isTopType) TypeAlias (arg.loBound | rebase(pbounds.loBound))
21272131 else arg recoverable_& rebase(pbounds)
21282132 case arg => TypeAlias (arg)
@@ -2285,7 +2289,7 @@ object Types {
22852289 if (base.isAnd == variance >= 0 ) tp1 & tp2 else tp1 | tp2
22862290 case _ =>
22872291 if (pre.termSymbol.is(Package )) argForParam(pre.select(nme.PACKAGE ))
2288- else if (pre.isBottomType ) pre
2292+ else if (pre.isNothingType ) pre
22892293 else NoType
22902294 }
22912295 }
@@ -2304,7 +2308,7 @@ object Types {
23042308 */
23052309 def derivedSelect (prefix : Type )(using Context ): Type =
23062310 if (prefix eq this .prefix) this
2307- else if (prefix.isBottomType ) prefix
2311+ else if (prefix.isNothingType ) prefix
23082312 else {
23092313 if (isType) {
23102314 val res =
@@ -4288,7 +4292,7 @@ object Types {
42884292
42894293 /** For uninstantiated type variables: Is the lower bound different from Nothing? */
42904294 def hasLowerBound (using Context ): Boolean =
4291- ! ctx.typerState.constraint.entry(origin).loBound.isBottomType
4295+ ! ctx.typerState.constraint.entry(origin).loBound.isNothingType
42924296
42934297 /** For uninstantiated type variables: Is the upper bound different from Any? */
42944298 def hasUpperBound (using Context ): Boolean =
@@ -5293,7 +5297,7 @@ object Types {
52935297 case _ =>
52945298 def propagate (lo : Type , hi : Type ) =
52955299 range(derivedRefinedType(tp, parent, lo), derivedRefinedType(tp, parent, hi))
5296- if (parent.isBottomType ) parent
5300+ if (parent.isNothingType ) parent
52975301 else info match {
52985302 case Range (infoLo : TypeBounds , infoHi : TypeBounds ) =>
52995303 assert(variance == 0 )
@@ -5386,7 +5390,7 @@ object Types {
53865390 case Range (lo, hi) =>
53875391 range(tp.derivedAnnotatedType(lo, annot), tp.derivedAnnotatedType(hi, annot))
53885392 case _ =>
5389- if (underlying.isBottomType ) underlying
5393+ if (underlying.isNothingType ) underlying
53905394 else tp.derivedAnnotatedType(underlying, annot)
53915395 }
53925396 override protected def derivedWildcardType (tp : WildcardType , bounds : Type ): WildcardType =
@@ -5634,7 +5638,7 @@ object Types {
56345638 else {
56355639 seen += tp
56365640 tp match {
5637- case tp if tp.isTopType || tp.isBottomType =>
5641+ case tp if tp.isTopType || tp.isNothingType =>
56385642 cs
56395643 case tp : AppliedType =>
56405644 foldOver(cs + tp.typeSymbol, tp)
0 commit comments