Skip to content

Commit 3d0aa82

Browse files
committed
Alternative fix: Don't use derivesFrom in isBottomType
1 parent 0723400 commit 3d0aa82

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff 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 _ =>

0 commit comments

Comments
 (0)