Skip to content

Commit c9e36fb

Browse files
committed
Generalize isNotNull
1 parent 11961bb commit c9e36fb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,15 @@ object Types {
218218
* For the moment this is only true for modules, but it could
219219
* be refined later.
220220
*/
221-
final def isNotNull(implicit ctx: Context): Boolean =
222-
classSymbol is ModuleClass
221+
final def isNotNull(implicit ctx: Context): Boolean = this match {
222+
case tp: ConstantType => tp.value.value != null
223+
case tp: ClassInfo => !tp.cls.isNullableClass && tp.cls != defn.NothingClass
224+
case tp: TypeBounds => tp.lo.isNotNull
225+
case tp: TypeProxy => tp.underlying.isNotNull
226+
case AndType(tp1, tp2) => tp1.isNotNull || tp2.isNotNull
227+
case OrType(tp1, tp2) => tp1.isNotNull && tp2.isNotNull
228+
case _ => false
229+
}
223230

224231
/** Is this type produced as a repair for an error? */
225232
final def isError(implicit ctx: Context): Boolean = stripTypeVar match {

0 commit comments

Comments
 (0)