Skip to content

Commit 811ab6d

Browse files
committed
Fix bootstrapping
1 parent 45c6227 commit 811ab6d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ object Types {
12231223
* then the top-level union isn't widened. This is needed so that type inference can infer nullable types.
12241224
*/
12251225
def widenUnion(using Context): Type = widen match
1226-
case tp @ OrNull(tp1): OrType =>
1226+
case tp @ OrNull(tp1) =>
12271227
// Don't widen `T|Null`, since otherwise we wouldn't be able to infer nullable unions.
12281228
val tp1Widen = tp1.widenUnionWithoutNull
12291229
if (tp1Widen.isRef(defn.AnyClass)) tp1Widen
@@ -3158,7 +3158,7 @@ object Types {
31583158
object OrNull {
31593159
def apply(tp: Type)(using Context) =
31603160
OrType(tp, defn.NullType, soft = false)
3161-
def unapply(tp: Type)(using Context): Option[Type] =
3161+
def unapply(tp: OrType)(using Context): Option[Type] =
31623162
if (ctx.explicitNulls) {
31633163
val tp1 = tp.stripNull()
31643164
if tp1 ne tp then Some(tp1) else None

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,17 @@ class Typer extends Namer
425425
* (x: T | Null) => x.$asInstanceOf$[x.type & T]
426426
*/
427427
def toNotNullTermRef(tree: Tree, pt: Type)(using Context): Tree = tree.tpe match
428-
case ref @ OrNull(tpnn) : TermRef
428+
case ref: TermRef
429429
if pt != AssignProto && // Ensure it is not the lhs of Assign
430430
ctx.notNullInfos.impliesNotNull(ref) &&
431431
// If a reference is in the context, it is already trackable at the point we add it.
432432
// Hence, we don't use isTracked in the next line, because checking use out of order is enough.
433433
!ref.usedOutOfOrder =>
434-
tree.select(defn.Any_typeCast).appliedToType(AndType(ref, tpnn))
434+
ref.widenSingleton match
435+
case OrNull(tpnn) =>
436+
tree.select(defn.Any_typeCast).appliedToType(AndType(ref, tpnn))
437+
case _ =>
438+
tree
435439
case _ =>
436440
tree
437441

0 commit comments

Comments
 (0)