Skip to content

Commit 9a0102b

Browse files
committed
Some small changes
1 parent 5a9b30b commit 9a0102b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object NullOpsDecorator {
2020
def stripNullWhenExplicit(using Context): Type = {
2121
def strip(tp: Type): Type =
2222
val tpWiden = tp.widenDealias
23-
val tpStriped = tpWiden match {
23+
val tpStripped = tpWiden match {
2424
case tp @ OrType(lhs, rhs) =>
2525
val llhs = strip(lhs)
2626
val rrhs = strip(rhs)
@@ -40,7 +40,7 @@ object NullOpsDecorator {
4040
tp.derivedTypeBounds(strip(lo), strip(hi))
4141
case tp => tp
4242
}
43-
if tpStriped ne tpWiden then tpStriped else tp
43+
if tpStripped ne tpWiden then tpStripped else tp
4444

4545
if ctx.explicitNulls then strip(self) else self
4646
}
@@ -51,7 +51,10 @@ object NullOpsDecorator {
5151
stripped ne self
5252
}
5353

54-
/** If a type is nullable after erasure */
54+
/** Types nullable after erasure are:
55+
* - Null itself
56+
* - Any type that is a subtype of `Object`, excluding `Nothing`
57+
*/
5558
def isNullableAfterErasure(using Context): Boolean =
5659
self.isNullType
5760
|| !self.isNothingType

compiler/src/dotty/tools/dotc/typer/Nullables.scala

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,22 @@ object Nullables:
2727
// We cannot check if hi is nullable, because it can cause cyclic reference.
2828

2929
/** Create a nullable type bound
30-
* If the lo is `Null`, `| Null` is added to hi
30+
* If lo is `Null`, `| Null` is added to hi
3131
*/
3232
def createNullableTypeBounds(lo: Type, hi: Type)(using Context): TypeBounds =
3333
val newHi = if needNullifyHi(lo, hi) then OrType(hi, defn.NullType, soft = false) else hi
3434
TypeBounds(lo, newHi)
3535

36-
3736
/** Create a nullable type bound tree
38-
* If the lo is `Null`, `| Null` is added to hi
37+
* If lo is `Null`, `| Null` is added to hi
3938
*/
4039
def createNullableTypeBoundsTree(lo: Tree, hi: Tree, alias: Tree = EmptyTree)(using Context): TypeBoundsTree =
4140
val hiTpe = hi.typeOpt
4241
val newHi = if needNullifyHi(lo.typeOpt, hiTpe) then TypeTree(OrType(hiTpe, defn.NullType, soft = false)) else hi
4342
TypeBoundsTree(lo, newHi, alias)
4443

4544
/** Use unsafe nulls subtyping where `Null` is a subtype of all reference types */
46-
inline def useUnsafeNullsSubTypeIf[T](cond: Boolean)(inline op: Context ?=> T)(using Context): T =
45+
inline def useUnsafeNullsSubTypeIf[T](inline cond: Boolean)(inline op: Context ?=> T)(using Context): T =
4746
val c = if cond then ctx.addMode(Mode.UnsafeNullsSubType) else ctx
4847
op(using c)
4948

0 commit comments

Comments
 (0)