@@ -239,7 +239,11 @@ object Types {
239
239
case tp : AndType =>
240
240
loop(tp.tp1) || loop(tp.tp2)
241
241
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))
243
247
case tp : JavaArrayType =>
244
248
cls == defn.ObjectClass
245
249
case _ =>
@@ -262,7 +266,7 @@ object Types {
262
266
}
263
267
264
268
/** 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 {
266
270
case tp : TypeRef =>
267
271
tp.name == tpnme.Nothing && (tp.symbol eq defn.NothingClass )
268
272
case _ => false
@@ -2122,7 +2126,7 @@ object Types {
2122
2126
case arg : TypeBounds =>
2123
2127
val v = param.paramVarianceSign
2124
2128
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))
2126
2130
else if (v < 0 && pbounds.hiBound.dealiasKeepAnnots.isTopType) TypeAlias (arg.loBound | rebase(pbounds.loBound))
2127
2131
else arg recoverable_& rebase(pbounds)
2128
2132
case arg => TypeAlias (arg)
@@ -2285,7 +2289,7 @@ object Types {
2285
2289
if (base.isAnd == variance >= 0 ) tp1 & tp2 else tp1 | tp2
2286
2290
case _ =>
2287
2291
if (pre.termSymbol.is(Package )) argForParam(pre.select(nme.PACKAGE ))
2288
- else if (pre.isBottomType ) pre
2292
+ else if (pre.isNothingType ) pre
2289
2293
else NoType
2290
2294
}
2291
2295
}
@@ -2304,7 +2308,7 @@ object Types {
2304
2308
*/
2305
2309
def derivedSelect (prefix : Type )(using Context ): Type =
2306
2310
if (prefix eq this .prefix) this
2307
- else if (prefix.isBottomType ) prefix
2311
+ else if (prefix.isNothingType ) prefix
2308
2312
else {
2309
2313
if (isType) {
2310
2314
val res =
@@ -4288,7 +4292,7 @@ object Types {
4288
4292
4289
4293
/** For uninstantiated type variables: Is the lower bound different from Nothing? */
4290
4294
def hasLowerBound (using Context ): Boolean =
4291
- ! ctx.typerState.constraint.entry(origin).loBound.isBottomType
4295
+ ! ctx.typerState.constraint.entry(origin).loBound.isNothingType
4292
4296
4293
4297
/** For uninstantiated type variables: Is the upper bound different from Any? */
4294
4298
def hasUpperBound (using Context ): Boolean =
@@ -5293,7 +5297,7 @@ object Types {
5293
5297
case _ =>
5294
5298
def propagate (lo : Type , hi : Type ) =
5295
5299
range(derivedRefinedType(tp, parent, lo), derivedRefinedType(tp, parent, hi))
5296
- if (parent.isBottomType ) parent
5300
+ if (parent.isNothingType ) parent
5297
5301
else info match {
5298
5302
case Range (infoLo : TypeBounds , infoHi : TypeBounds ) =>
5299
5303
assert(variance == 0 )
@@ -5386,7 +5390,7 @@ object Types {
5386
5390
case Range (lo, hi) =>
5387
5391
range(tp.derivedAnnotatedType(lo, annot), tp.derivedAnnotatedType(hi, annot))
5388
5392
case _ =>
5389
- if (underlying.isBottomType ) underlying
5393
+ if (underlying.isNothingType ) underlying
5390
5394
else tp.derivedAnnotatedType(underlying, annot)
5391
5395
}
5392
5396
override protected def derivedWildcardType (tp : WildcardType , bounds : Type ): WildcardType =
@@ -5634,7 +5638,7 @@ object Types {
5634
5638
else {
5635
5639
seen += tp
5636
5640
tp match {
5637
- case tp if tp.isTopType || tp.isBottomType =>
5641
+ case tp if tp.isTopType || tp.isNothingType =>
5638
5642
cs
5639
5643
case tp : AppliedType =>
5640
5644
foldOver(cs + tp.typeSymbol, tp)
0 commit comments