Skip to content

Commit 969a224

Browse files
committed
Rewrite isNullableType
1 parent 33b7bc3 commit 969a224

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,19 @@ object NullOpsDecorator {
6161
/** Can the type has null value after erasure?
6262
* TODO
6363
*/
64-
def isNullableAfterErasure(using Context): Boolean = self match {
65-
case tp: ClassInfo => tp.cls.isNullableClassAfterErasure
66-
case tp: TypeProxy => tp.underlying.isNullableAfterErasure
67-
case OrType(lhs, rhs) =>
68-
lhs.isNullableAfterErasure || rhs.isNullableAfterErasure
69-
case AndType(lhs, rhs) =>
70-
lhs.isNullableAfterErasure && rhs.isNullableAfterErasure
71-
case _ =>
72-
self.isNullType || self <:< defn.ObjectType
73-
}
64+
// def isNullableAfterErasure(using Context): Boolean = self match {
65+
// case tp: ClassInfo => tp.cls.isNullableClassAfterErasure
66+
// case tp: TypeProxy => tp.underlying.isNullableAfterErasure
67+
// case OrType(lhs, rhs) =>
68+
// lhs.isNullableAfterErasure || rhs.isNullableAfterErasure
69+
// case AndType(lhs, rhs) =>
70+
// lhs.isNullableAfterErasure && rhs.isNullableAfterErasure
71+
// case _ =>
72+
// self.isNullType || self <:< defn.ObjectType
73+
// }
74+
def isNullableAfterErasure(using Context): Boolean =
75+
self.isNullType
76+
|| !self.isNothingType
77+
&& self.derivesFrom(defn.ObjectClass, afterErasure = true)
7478
}
7579
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,9 @@ object SymDenotations {
17911791
derivesFrom(base) ||
17921792
base.isClass && (
17931793
(symbol eq defn.NothingClass) ||
1794-
(symbol eq defn.NullClass) && (base ne defn.NothingClass))
1794+
(!ctx.explicitNulls || ctx.phase.erasedTypes)
1795+
&& (symbol eq defn.NullClass)
1796+
&& (base ne defn.NothingClass))
17951797

17961798
/** Is it possible that a class inherits both `this` and `that`?
17971799
*

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,9 @@ object Types {
15911591
/** Is this (an alias of) the `scala.Null` type? */
15921592
final def isNullType(using Context) = isRef(defn.NullClass)
15931593

1594+
/** Is this (an alias of) the `scala.Nothing` type? */
1595+
final def isNothingType(using Context) = isRef(defn.NothingClass)
1596+
15941597
/** The resultType of a LambdaType, or ExprType, the type itself for others */
15951598
def resultType(using Context): Type = this
15961599

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import dotty.tools.dotc.core.CheckRealizable
1010
import dotty.tools.dotc.core.Decorators._
1111
import dotty.tools.dotc.core.Denotations.SingleDenotation
1212
import dotty.tools.dotc.core.Flags._
13+
import dotty.tools.dotc.core.{Mode => CMode}
1314
import dotty.tools.dotc.core.Names.{Name, TermName}
1415
import dotty.tools.dotc.core.NameKinds.SimpleNameKind
1516
import dotty.tools.dotc.core.NameOps._
@@ -252,7 +253,7 @@ object Completion {
252253
}
253254

254255
// 2. The extension method is a member of some given instance that is visible at the point of the reference.
255-
val givensInScope = ctx.implicits.eligible(defn.AnyType).map(_.implicitRef.underlyingRef)
256+
val givensInScope = ctx.implicits.eligible(defn.AnyType, ctx.mode.is(CMode.UnsafeNullConversion)).map(_.implicitRef.underlyingRef)
256257
val extMethodsFromGivensInScope = extractDefinedExtensionMethods(givensInScope)
257258

258259
// 3. The reference is of the form r.m and the extension method is defined in the implicit scope of the type of r.

0 commit comments

Comments
 (0)