Skip to content

Commit ad580ce

Browse files
committed
Rewrite isNullableType
1 parent 6141284 commit ad580ce

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
@@ -1790,7 +1790,9 @@ object SymDenotations {
17901790
derivesFrom(base) ||
17911791
base.isClass && (
17921792
(symbol eq defn.NothingClass) ||
1793-
(symbol eq defn.NullClass) && (base ne defn.NothingClass))
1793+
(!ctx.explicitNulls || ctx.phase.erasedTypes)
1794+
&& (symbol eq defn.NullClass)
1795+
&& (base ne defn.NothingClass))
17941796

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

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

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

1576+
/** Is this (an alias of) the `scala.Nothing` type? */
1577+
final def isNothingType(using Context) = isRef(defn.NothingClass)
1578+
15761579
/** The resultType of a LambdaType, or ExprType, the type itself for others */
15771580
def resultType(using Context): Type = this
15781581

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)