File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -1175,11 +1175,11 @@ class Definitions {
11751175 def isBottomClassAfterErasure (cls : Symbol ): Boolean = cls == NothingClass || cls == NullClass
11761176
11771177 def isBottomType (tp : Type ): Boolean =
1178- if (ctx.explicitNulls && ! ctx.phase.erasedTypes) tp.derivesFrom (NothingClass )
1178+ if (ctx.explicitNulls && ! ctx.phase.erasedTypes) tp.isCombinedRef (NothingClass )
11791179 else isBottomTypeAfterErasure(tp)
11801180
11811181 def isBottomTypeAfterErasure (tp : Type ): Boolean =
1182- tp.derivesFrom (NothingClass ) || tp.derivesFrom (NullClass )
1182+ tp.isCombinedRef (NothingClass ) || tp.isCombinedRef (NullClass )
11831183
11841184 /** Is a function class.
11851185 * - FunctionXXL
Original file line number Diff line number Diff line change @@ -205,6 +205,12 @@ object Types {
205205 false
206206 }
207207
208+ /** Like isRef, but also extends to unions and intersections */
209+ def isCombinedRef (sym : Symbol )(using Context ): Boolean = stripped match
210+ case AndType (tp1 : Type , tp2 : Type ) => tp1.isRef(sym) || tp2.isRef(sym)
211+ case OrType (tp1 : Type , tp2 : Type ) => tp1.isRef(sym) && tp2.isRef(sym)
212+ case _ => isRef(sym)
213+
208214 def isAny (using Context ): Boolean = isRef(defn.AnyClass , skipRefined = false )
209215 def isAnyRef (using Context ): Boolean = isRef(defn.ObjectClass , skipRefined = false )
210216 def isAnyKind (using Context ): Boolean = isRef(defn.AnyKindClass , skipRefined = false )
@@ -242,9 +248,8 @@ object Types {
242248 // If the type is `T | Null` or `T | Nothing`, and `T` derivesFrom the class,
243249 // then the OrType derivesFrom the class. Otherwise, we need to check both sides
244250 // derivesFrom the class.
245- loop(tp.tp1) && loop(tp.tp2)
246- || tp.tp1.isNullOrNothingType && loop(tp.tp2)
247- || tp.tp2.isNullOrNothingType && loop(tp.tp1)
251+ loop(tp.tp1) && (loop(tp.tp2) || defn.isBottomType(tp.tp2))
252+ || defn.isBottomType(tp.tp1) && loop(tp.tp2)
248253 case tp : JavaArrayType =>
249254 cls == defn.ObjectClass
250255 case _ =>
You can’t perform that action at this time.
0 commit comments