File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -1223,7 +1223,7 @@ object Types {
1223
1223
* then the top-level union isn't widened. This is needed so that type inference can infer nullable types.
1224
1224
*/
1225
1225
def widenUnion (using Context ): Type = widen match
1226
- case tp @ OrNull (tp1): OrType =>
1226
+ case tp @ OrNull (tp1) =>
1227
1227
// Don't widen `T|Null`, since otherwise we wouldn't be able to infer nullable unions.
1228
1228
val tp1Widen = tp1.widenUnionWithoutNull
1229
1229
if (tp1Widen.isRef(defn.AnyClass )) tp1Widen
@@ -3158,7 +3158,7 @@ object Types {
3158
3158
object OrNull {
3159
3159
def apply (tp : Type )(using Context ) =
3160
3160
OrType (tp, defn.NullType , soft = false )
3161
- def unapply (tp : Type )(using Context ): Option [Type ] =
3161
+ def unapply (tp : OrType )(using Context ): Option [Type ] =
3162
3162
if (ctx.explicitNulls) {
3163
3163
val tp1 = tp.stripNull()
3164
3164
if tp1 ne tp then Some (tp1) else None
Original file line number Diff line number Diff line change @@ -425,13 +425,17 @@ class Typer extends Namer
425
425
* (x: T | Null) => x.$asInstanceOf$[x.type & T]
426
426
*/
427
427
def toNotNullTermRef (tree : Tree , pt : Type )(using Context ): Tree = tree.tpe match
428
- case ref @ OrNull (tpnn) : TermRef
428
+ case ref : TermRef
429
429
if pt != AssignProto && // Ensure it is not the lhs of Assign
430
430
ctx.notNullInfos.impliesNotNull(ref) &&
431
431
// If a reference is in the context, it is already trackable at the point we add it.
432
432
// Hence, we don't use isTracked in the next line, because checking use out of order is enough.
433
433
! ref.usedOutOfOrder =>
434
- tree.select(defn.Any_typeCast ).appliedToType(AndType (ref, tpnn))
434
+ ref.widenDealias match
435
+ case OrNull (tpnn) =>
436
+ tree.select(defn.Any_typeCast ).appliedToType(AndType (ref, tpnn))
437
+ case _ =>
438
+ tree
435
439
case _ =>
436
440
tree
437
441
You can’t perform that action at this time.
0 commit comments