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 {
1175
1175
def isBottomClassAfterErasure (cls : Symbol ): Boolean = cls == NothingClass || cls == NullClass
1176
1176
1177
1177
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 )
1179
1179
else isBottomTypeAfterErasure(tp)
1180
1180
1181
1181
def isBottomTypeAfterErasure (tp : Type ): Boolean =
1182
- tp.derivesFrom (NothingClass ) || tp.derivesFrom (NullClass )
1182
+ tp.isCombinedRef (NothingClass ) || tp.isCombinedRef (NullClass )
1183
1183
1184
1184
/** Is a function class.
1185
1185
* - FunctionXXL
Original file line number Diff line number Diff line change @@ -205,6 +205,12 @@ object Types {
205
205
false
206
206
}
207
207
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
+
208
214
def isAny (using Context ): Boolean = isRef(defn.AnyClass , skipRefined = false )
209
215
def isAnyRef (using Context ): Boolean = isRef(defn.ObjectClass , skipRefined = false )
210
216
def isAnyKind (using Context ): Boolean = isRef(defn.AnyKindClass , skipRefined = false )
@@ -242,9 +248,8 @@ object Types {
242
248
// If the type is `T | Null` or `T | Nothing`, and `T` derivesFrom the class,
243
249
// then the OrType derivesFrom the class. Otherwise, we need to check both sides
244
250
// 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)
248
253
case tp : JavaArrayType =>
249
254
cls == defn.ObjectClass
250
255
case _ =>
You can’t perform that action at this time.
0 commit comments