File tree 2 files changed +20
-12
lines changed
tests/pos-with-compiler-cc/dotc
2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -1289,11 +1289,15 @@ object Types {
1289
1289
* then the top-level union isn't widened. This is needed so that type inference can infer nullable types.
1290
1290
*/
1291
1291
def widenUnion (using Context ): Type = widen match
1292
- case tp @ OrNull (tp1): OrType =>
1293
- // Don't widen `T|Null`, since otherwise we wouldn't be able to infer nullable unions.
1294
- val tp1Widen = tp1.widenUnionWithoutNull
1295
- if (tp1Widen.isRef(defn.AnyClass )) tp1Widen
1296
- else tp.derivedOrType(tp1Widen, defn.NullType )
1292
+ case tp @ OrNull (tp1) =>
1293
+ tp match
1294
+ case tp : OrType =>
1295
+ // Don't widen `T|Null`, since otherwise we wouldn't be able to infer nullable unions.
1296
+ val tp1Widen = tp1.widenUnionWithoutNull
1297
+ if (tp1Widen.isRef(defn.AnyClass )) tp1Widen
1298
+ else tp.derivedOrType(tp1Widen, defn.NullType )
1299
+ case _ =>
1300
+ tp.widenUnionWithoutNull
1297
1301
case tp =>
1298
1302
tp.widenUnionWithoutNull
1299
1303
Original file line number Diff line number Diff line change @@ -477,13 +477,17 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
477
477
* (x: T | Null) => x.$asInstanceOf$[x.type & T]
478
478
*/
479
479
def toNotNullTermRef (tree : Tree , pt : Type )(using Context ): Tree = tree.tpe match
480
- case ref @ OrNull (tpnn) : TermRef
481
- if pt != AssignProto && // Ensure it is not the lhs of Assign
482
- ctx.notNullInfos.impliesNotNull(ref) &&
483
- // If a reference is in the context, it is already trackable at the point we add it.
484
- // Hence, we don't use isTracked in the next line, because checking use out of order is enough.
485
- ! ref.usedOutOfOrder =>
486
- tree.cast(AndType (ref, tpnn))
480
+ case tp @ OrNull (tpnn) =>
481
+ tp match
482
+ case ref : TermRef
483
+ if pt != AssignProto && // Ensure it is not the lhs of Assign
484
+ ctx.notNullInfos.impliesNotNull(ref) &&
485
+ // If a reference is in the context, it is already trackable at the point we add it.
486
+ // Hence, we don't use isTracked in the next line, because checking use out of order is enough.
487
+ ! ref.usedOutOfOrder =>
488
+ tree.cast(AndType (ref, tpnn))
489
+ case _ =>
490
+ tree
487
491
case _ =>
488
492
tree
489
493
You can’t perform that action at this time.
0 commit comments