@@ -71,7 +71,7 @@ sealed abstract class GadtConstraint extends Showable {
71
71
def resetScrutineePath (): Unit
72
72
73
73
/** Set the scrutinee path. */
74
- def withScrutineePath [T ](path : TermRef )(op : => T ): T
74
+ def withScrutineePath [T ](path : TermRef | Null )(op : => T ): T
75
75
76
76
/** Is the symbol registered in the constraint?
77
77
*
@@ -113,7 +113,7 @@ final class ProperGadtConstraint private(
113
113
private var pathDepMapping : SimpleIdentityMap [PathType , SimpleIdentityMap [Symbol , TypeVar ]],
114
114
private var pathDepReverseMapping : SimpleIdentityMap [TypeParamRef , TypeRef ],
115
115
private var wasConstrained : Boolean ,
116
- private var myScrutineePath : TermRef ,
116
+ private var myScrutineePath : TermRef | Null ,
117
117
private var myUnionFind : SimpleIdentityMap [PathType , PathType ]
118
118
) extends GadtConstraint with ConstraintHandling {
119
119
import dotty .tools .dotc .config .Printers .{gadts , gadtsConstr }
@@ -183,7 +183,7 @@ final class ProperGadtConstraint private(
183
183
val tp1 = left.externalize(p1)
184
184
right.tvarOf(tp1) match {
185
185
case null =>
186
- case tvar2 =>
186
+ case tvar2 : TypeVar =>
187
187
mapping1 = mapping1.updated(p1, tvar2.origin)
188
188
mapping2 = mapping2.updated(tvar2.origin, p1)
189
189
}
@@ -194,7 +194,7 @@ final class ProperGadtConstraint private(
194
194
def mapTypeParam (m : SimpleIdentityMap [TypeParamRef , TypeParamRef ])(tpr : TypeParamRef ) =
195
195
m(tpr) match
196
196
case null => tpr
197
- case tpr1 => tpr1
197
+ case tpr1 : TypeParamRef => tpr1
198
198
199
199
(mapTypeParam(mapping1), mapTypeParam(mapping2))
200
200
}
@@ -297,7 +297,7 @@ final class ProperGadtConstraint private(
297
297
private def tvarOf (path : PathType , sym : Symbol )(using Context ): TypeVar | Null =
298
298
pathDepMapping(path) match
299
299
case null => null
300
- case innerMapping => innerMapping(sym)
300
+ case innerMapping => innerMapping.nn (sym)
301
301
302
302
/** Try to retrieve type variable for some TypeRef.
303
303
* Both type parameters and path-dependent types are considered.
@@ -391,7 +391,7 @@ final class ProperGadtConstraint private(
391
391
pathDepMapping = pathDepMapping.updated(path, {
392
392
val old : SimpleIdentityMap [Symbol , TypeVar ] = pathDepMapping(path) match
393
393
case null => SimpleIdentityMap .empty
394
- case m => m
394
+ case m => m.nn
395
395
396
396
old.updated(sym, tv)
397
397
})
@@ -552,28 +552,30 @@ final class ProperGadtConstraint private(
552
552
private def lookupPath (p : PathType ): PathType | Null =
553
553
def recur (p : PathType , steps : Int = 0 ): PathType | Null = myUnionFind(p) match
554
554
case null => null
555
- case q if p eq q => q
556
- case q =>
555
+ case q : PathType if q eq p => q
556
+ case q : PathType =>
557
557
if steps <= 1024 then
558
558
recur(q, steps + 1 )
559
559
else
560
560
assert(false , " lookup step exceeding the threshold, possibly because of a loop in the union find" )
561
561
recur(p)
562
562
563
563
override def addEquality (p : PathType , q : PathType ): Unit =
564
- val newRep = lookupPath(p) match
564
+ val newRep : PathType = lookupPath(p) match
565
565
case null => lookupPath(q) match
566
566
case null => p
567
- case r => r
568
- case r => r
567
+ case r : PathType => r
568
+ case r : PathType => r
569
569
570
570
myUnionFind = myUnionFind.updated(p, newRep)
571
571
myUnionFind = myUnionFind.updated(q, newRep)
572
572
573
573
override def isEquivalent (p : PathType , q : PathType ): Boolean =
574
574
lookupPath(p) match
575
575
case null => false
576
- case p0 => p0 eq lookupPath(q)
576
+ case p0 : PathType => lookupPath(q) match
577
+ case null => false
578
+ case q0 : PathType => p0 eq q0
577
579
578
580
override def isLess (sym1 : Symbol , sym2 : Symbol )(using Context ): Boolean =
579
581
constraint.isLess(tvarOrError(sym1).origin, tvarOrError(sym2).origin)
@@ -593,7 +595,7 @@ final class ProperGadtConstraint private(
593
595
override def fullBounds (p : PathType , sym : Symbol )(using Context ): TypeBounds | Null =
594
596
tvarOf(p, sym) match {
595
597
case null => null
596
- case tv => fullBounds(tv.origin)
598
+ case tv => fullBounds(tv.nn. origin)
597
599
}
598
600
599
601
override def fullBounds (tp : TypeRef )(using Context ): TypeBounds | Null =
@@ -622,7 +624,7 @@ final class ProperGadtConstraint private(
622
624
case TypeAlias (tpr : TypeParamRef ) if reverseMapping.contains(tpr) =>
623
625
TypeAlias (reverseMapping(tpr).nn.typeRef)
624
626
case TypeAlias (tpr : TypeParamRef ) if pathDepReverseMapping.contains(tpr) =>
625
- TypeAlias (pathDepReverseMapping(tpr))
627
+ TypeAlias (pathDepReverseMapping(tpr).nn )
626
628
case tb => tb
627
629
}
628
630
retrieveBounds
@@ -640,7 +642,7 @@ final class ProperGadtConstraint private(
640
642
641
643
override def contains (path : PathType , sym : Symbol )(using Context ): Boolean = pathDepMapping(path) match
642
644
case null => false
643
- case innerMapping => innerMapping(sym) != null
645
+ case innerMapping => innerMapping.nn (sym) != null
644
646
645
647
override def registeredTypeMembers (path : PathType ): List [Symbol ] = pathDepMapping(path).nn.keys
646
648
@@ -690,7 +692,7 @@ final class ProperGadtConstraint private(
690
692
691
693
override def resetScrutineePath (): Unit = myScrutineePath = null
692
694
693
- override def withScrutineePath [T ](path : TermRef )(op : => T ): T =
695
+ override def withScrutineePath [T ](path : TermRef | Null )(op : => T ): T =
694
696
val saved = this .myScrutineePath
695
697
this .myScrutineePath = path
696
698
val result = op
@@ -826,7 +828,7 @@ final class ProperGadtConstraint private(
826
828
827
829
override def resetScrutineePath (): Unit = ()
828
830
829
- override def withScrutineePath [T ](path : TermRef )(op : => T ): T = op
831
+ override def withScrutineePath [T ](path : TermRef | Null )(op : => T ): T = op
830
832
831
833
override def fresh = new ProperGadtConstraint
832
834
override def restore (other : GadtConstraint ): Unit =
0 commit comments