diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index c251b668c32d..be85cecfd548 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -962,8 +962,16 @@ class Definitions { name.length > prefix.length && name.drop(prefix.length).forall(_.isDigit)) - def isBottomClass(cls: Symbol) = cls == NothingClass - def isBottomType(tp: Type) = tp.derivesFrom(NothingClass) + def isBottomClass(cls: Symbol) = { + // After erasure, reference types become nullable again. + if (ctx.phaseId <= ctx.erasurePhase.id) cls == NothingClass + else cls == NothingClass || cls == NullClass + } + def isBottomType(tp: Type) = { + // After erasure, reference types become nullable again. + if (ctx.phaseId <= ctx.erasurePhase.id) tp.derivesFrom(NothingClass) + else tp.derivesFrom(NothingClass) || tp.derivesFrom(NullClass) + } /** Is a function class. * - FunctionN for N >= 0 diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index b772ba009d8a..aa15aa043775 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -657,8 +657,12 @@ object SymDenotations { } /** Is this symbol a class with nullable values? */ - final def isNullableClass(implicit ctx: Context): Boolean = - symbol == defn.NullClass || symbol == defn.AnyRefAlias || symbol == defn.AnyClass + final def isNullableClass(implicit ctx: Context): Boolean = { + // After erasure, reference types become nullable again. + if (ctx.phaseId <= ctx.erasurePhase.id) symbol == defn.NullClass || symbol == defn.AnyRefAlias || symbol == defn.AnyClass + else isClass && !isValueClass && !is(ModuleClass) && symbol != defn.NothingClass + } + /** Is this definition accessible as a member of tree with type `pre`? * @param pre The type of the tree from which the selection is made diff --git a/tests/pos/i536.scala b/tests/pos/i536.scala index 49d8f6058be3..1ea41d9e9da9 100644 --- a/tests/pos/i536.scala +++ b/tests/pos/i536.scala @@ -2,11 +2,11 @@ trait Comp[T] trait Coll[T] class C extends Comp[C] object Max { - def max[M <: Comp[_ >: M]](x: Coll[_ <: M] | Null): M = ??? + def max[M <: Comp[_ >: M]](x: Coll[_ <: M]): M = ??? def max[M](x: Coll[_ <: M], cmp: Object): M = ??? val xs: Coll[C] = ??? val m1 = max(xs) - val m2 = max(null) + val m2 = max(???) java.util.Collections.max(null) }