@@ -209,7 +209,27 @@ object Types {
209209 def isAnyRef (using Context ): Boolean = isRef(defn.ObjectClass , skipRefined = false )
210210 def isAnyKind (using Context ): Boolean = isRef(defn.AnyKindClass , skipRefined = false )
211211
212- def isFromJavaObject (using Context ): Boolean = typeSymbol eq defn.FromJavaObjectSymbol
212+ /** Is this type exactly Nothing (no vars, aliases, refinements etc allowed)? */
213+ def isExactlyNothing (using Context ): Boolean = this match {
214+ case tp : TypeRef =>
215+ tp.name == tpnme.Nothing && (tp.symbol eq defn.NothingClass )
216+ case _ => false
217+ }
218+
219+ /** Is this type exactly Any (no vars, aliases, refinements etc allowed)? */
220+ def isExactlyAny (using Context ): Boolean = this match {
221+ case tp : TypeRef =>
222+ tp.name == tpnme.Any && (tp.symbol eq defn.AnyClass )
223+ case _ => false
224+ }
225+
226+ def isBottomType (using Context ): Boolean =
227+ if ctx.explicitNulls && ! ctx.phase.erasedTypes then hasClassSymbol(defn.NothingClass )
228+ else isBottomTypeAfterErasure
229+
230+ def isBottomTypeAfterErasure (using Context ): Boolean =
231+ val d = defn
232+ hasClassSymbol(d.NothingClass ) || hasClassSymbol(d.NullClass )
213233
214234 /** Does this type refer exactly to class symbol `sym`, instead of to a subclass of `sym`?
215235 * Implemented like `isRef`, but follows more types: all type proxies as well as and- and or-types
@@ -244,9 +264,9 @@ object Types {
244264 // If the type is `T | Null` or `T | Nothing`, the class is != Nothing,
245265 // and `T` derivesFrom the class, then the OrType derivesFrom the class.
246266 // Otherwise, we need to check both sides derivesFrom the class.
247- if defn.isBottomType( tp.tp1) && cls != defn.NothingClass then
267+ if tp.tp1.isBottomType && cls != defn.NothingClass then
248268 loop(tp.tp2)
249- else if defn.isBottomType( tp.tp2) && cls != defn.NothingClass then
269+ else if tp.tp2.isBottomType && cls != defn.NothingClass then
250270 loop(tp.tp1)
251271 else
252272 loop(tp.tp1) && loop(tp.tp2)
@@ -258,6 +278,8 @@ object Types {
258278 loop(this )
259279 }
260280
281+ def isFromJavaObject (using Context ): Boolean = typeSymbol eq defn.FromJavaObjectSymbol
282+
261283 /** True iff `symd` is a denotation of a class type parameter and the reference
262284 * `<this> . <symd>` is an actual argument reference, i.e. `this` is different
263285 * from the ThisType of `symd`'s owner.
@@ -271,20 +293,6 @@ object Types {
271293 }
272294 }
273295
274- /** Is this type exactly Nothing (no vars, aliases, refinements etc allowed)? */
275- def isNothing (using Context ): Boolean = this match {
276- case tp : TypeRef =>
277- tp.name == tpnme.Nothing && (tp.symbol eq defn.NothingClass )
278- case _ => false
279- }
280-
281- /** Is this type exactly Any (no vars, aliases, refinements etc allowed)? */
282- def isTopType (using Context ): Boolean = this match {
283- case tp : TypeRef =>
284- tp.name == tpnme.Any && (tp.symbol eq defn.AnyClass )
285- case _ => false
286- }
287-
288296 /** Is this type a (possibly aliased) singleton type? */
289297 def isSingleton (using Context ): Boolean = dealias.isInstanceOf [SingletonType ]
290298
@@ -2156,8 +2164,8 @@ object Types {
21562164 case arg : TypeBounds =>
21572165 val v = param.paramVarianceSign
21582166 val pbounds = param.paramInfo
2159- if (v > 0 && pbounds.loBound.dealiasKeepAnnots.isNothing ) TypeAlias (arg.hiBound & rebase(pbounds.hiBound))
2160- else if (v < 0 && pbounds.hiBound.dealiasKeepAnnots.isTopType ) TypeAlias (arg.loBound | rebase(pbounds.loBound))
2167+ if (v > 0 && pbounds.loBound.dealiasKeepAnnots.isExactlyNothing ) TypeAlias (arg.hiBound & rebase(pbounds.hiBound))
2168+ else if (v < 0 && pbounds.hiBound.dealiasKeepAnnots.isExactlyAny ) TypeAlias (arg.loBound | rebase(pbounds.loBound))
21612169 else arg recoverable_& rebase(pbounds)
21622170 case arg => TypeAlias (arg)
21632171 }
@@ -2319,7 +2327,7 @@ object Types {
23192327 if (base.isAnd == variance >= 0 ) tp1 & tp2 else tp1 | tp2
23202328 case _ =>
23212329 if (pre.termSymbol.is(Package )) argForParam(pre.select(nme.PACKAGE ))
2322- else if (pre.isNothing ) pre
2330+ else if (pre.isExactlyNothing ) pre
23232331 else NoType
23242332 }
23252333 }
@@ -2338,7 +2346,7 @@ object Types {
23382346 */
23392347 def derivedSelect (prefix : Type )(using Context ): Type =
23402348 if (prefix eq this .prefix) this
2341- else if (prefix.isNothing ) prefix
2349+ else if (prefix.isExactlyNothing ) prefix
23422350 else {
23432351 if (isType) {
23442352 val res =
@@ -4326,7 +4334,7 @@ object Types {
43264334
43274335 /** For uninstantiated type variables: Is the lower bound different from Nothing? */
43284336 def hasLowerBound (using Context ): Boolean =
4329- ! ctx.typerState.constraint.entry(origin).loBound.isNothing
4337+ ! ctx.typerState.constraint.entry(origin).loBound.isExactlyNothing
43304338
43314339 /** For uninstantiated type variables: Is the upper bound different from Any? */
43324340 def hasUpperBound (using Context ): Boolean =
@@ -5331,7 +5339,7 @@ object Types {
53315339 case _ =>
53325340 def propagate (lo : Type , hi : Type ) =
53335341 range(derivedRefinedType(tp, parent, lo), derivedRefinedType(tp, parent, hi))
5334- if (parent.isNothing ) parent
5342+ if (parent.isExactlyNothing ) parent
53355343 else info match {
53365344 case Range (infoLo : TypeBounds , infoHi : TypeBounds ) =>
53375345 assert(variance == 0 )
@@ -5424,7 +5432,7 @@ object Types {
54245432 case Range (lo, hi) =>
54255433 range(tp.derivedAnnotatedType(lo, annot), tp.derivedAnnotatedType(hi, annot))
54265434 case _ =>
5427- if (underlying.isNothing ) underlying
5435+ if (underlying.isExactlyNothing ) underlying
54285436 else tp.derivedAnnotatedType(underlying, annot)
54295437 }
54305438 override protected def derivedWildcardType (tp : WildcardType , bounds : Type ): WildcardType =
@@ -5672,7 +5680,7 @@ object Types {
56725680 else {
56735681 seen += tp
56745682 tp match {
5675- case tp if tp.isTopType || tp.isNothing =>
5683+ case tp if tp.isExactlyAny || tp.isExactlyNothing =>
56765684 cs
56775685 case tp : AppliedType =>
56785686 foldOver(cs + tp.typeSymbol, tp)
0 commit comments