@@ -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
*
@@ -111,7 +111,7 @@ final class ProperGadtConstraint private(
111
111
private var pathDepMapping : SimpleIdentityMap [PathType , SimpleIdentityMap [Symbol , TypeVar ]],
112
112
private var pathDepReverseMapping : SimpleIdentityMap [TypeParamRef , TypeRef ],
113
113
private var wasConstrained : Boolean ,
114
- private var myScrutineePath : TermRef ,
114
+ private var myScrutineePath : TermRef | Null ,
115
115
private var myUnionFind : SimpleIdentityMap [PathType , PathType ]
116
116
) extends GadtConstraint with ConstraintHandling {
117
117
import dotty .tools .dotc .config .Printers .{gadts , gadtsConstr }
@@ -181,7 +181,7 @@ final class ProperGadtConstraint private(
181
181
val tp1 = left.externalize(p1)
182
182
right.tvarOf(tp1) match {
183
183
case null =>
184
- case tvar2 =>
184
+ case tvar2 : TypeVar =>
185
185
mapping1 = mapping1.updated(p1, tvar2.origin)
186
186
mapping2 = mapping2.updated(tvar2.origin, p1)
187
187
}
@@ -192,7 +192,7 @@ final class ProperGadtConstraint private(
192
192
def mapTypeParam (m : SimpleIdentityMap [TypeParamRef , TypeParamRef ])(tpr : TypeParamRef ) =
193
193
m(tpr) match
194
194
case null => tpr
195
- case tpr1 => tpr1
195
+ case tpr1 : TypeParamRef => tpr1
196
196
197
197
(mapTypeParam(mapping1), mapTypeParam(mapping2))
198
198
}
@@ -295,7 +295,7 @@ final class ProperGadtConstraint private(
295
295
private def tvarOf (path : PathType , sym : Symbol )(using Context ): TypeVar | Null =
296
296
pathDepMapping(path) match
297
297
case null => null
298
- case innerMapping => innerMapping(sym)
298
+ case innerMapping => innerMapping.nn (sym)
299
299
300
300
/** Try to retrieve type variable for some TypeRef.
301
301
* Both type parameters and path-dependent types are considered.
@@ -389,7 +389,7 @@ final class ProperGadtConstraint private(
389
389
pathDepMapping = pathDepMapping.updated(path, {
390
390
val old : SimpleIdentityMap [Symbol , TypeVar ] = pathDepMapping(path) match
391
391
case null => SimpleIdentityMap .empty
392
- case m => m
392
+ case m => m.nn
393
393
394
394
old.updated(sym, tv)
395
395
})
@@ -550,28 +550,30 @@ final class ProperGadtConstraint private(
550
550
private def lookupPath (p : PathType ): PathType | Null =
551
551
def recur (p : PathType , steps : Int = 0 ): PathType | Null = myUnionFind(p) match
552
552
case null => null
553
- case q if p eq q => q
554
- case q =>
553
+ case q : PathType if q eq p => q
554
+ case q : PathType =>
555
555
if steps <= 1024 then
556
556
recur(q, steps + 1 )
557
557
else
558
558
assert(false , " lookup step exceeding the threshold, possibly because of a loop in the union find" )
559
559
recur(p)
560
560
561
561
override def addEquality (p : PathType , q : PathType ): Unit =
562
- val newRep = lookupPath(p) match
562
+ val newRep : PathType = lookupPath(p) match
563
563
case null => lookupPath(q) match
564
564
case null => p
565
- case r => r
566
- case r => r
565
+ case r : PathType => r
566
+ case r : PathType => r
567
567
568
568
myUnionFind = myUnionFind.updated(p, newRep)
569
569
myUnionFind = myUnionFind.updated(q, newRep)
570
570
571
571
override def isEquivalent (p : PathType , q : PathType ): Boolean =
572
572
lookupPath(p) match
573
573
case null => false
574
- case p0 => p0 eq lookupPath(q)
574
+ case p0 : PathType => lookupPath(q) match
575
+ case null => false
576
+ case q0 : PathType => p0 eq q0
575
577
576
578
override def isLess (sym1 : Symbol , sym2 : Symbol )(using Context ): Boolean =
577
579
constraint.isLess(tvarOrError(sym1).origin, tvarOrError(sym2).origin)
@@ -591,7 +593,7 @@ final class ProperGadtConstraint private(
591
593
override def fullBounds (p : PathType , sym : Symbol )(using Context ): TypeBounds | Null =
592
594
tvarOf(p, sym) match {
593
595
case null => null
594
- case tv => fullBounds(tv.origin)
596
+ case tv => fullBounds(tv.nn. origin)
595
597
}
596
598
597
599
override def fullBounds (tp : TypeRef )(using Context ): TypeBounds | Null =
@@ -625,7 +627,7 @@ final class ProperGadtConstraint private(
625
627
case TypeAlias (tpr : TypeParamRef ) if reverseMapping.contains(tpr) =>
626
628
TypeAlias (reverseMapping(tpr).nn.typeRef)
627
629
case TypeAlias (tpr : TypeParamRef ) if pathDepReverseMapping.contains(tpr) =>
628
- TypeAlias (pathDepReverseMapping(tpr))
630
+ TypeAlias (pathDepReverseMapping(tpr).nn )
629
631
case tb => tb
630
632
}
631
633
retrieveBounds
@@ -643,7 +645,7 @@ final class ProperGadtConstraint private(
643
645
644
646
override def contains (path : PathType , sym : Symbol )(using Context ): Boolean = pathDepMapping(path) match
645
647
case null => false
646
- case innerMapping => innerMapping(sym) != null
648
+ case innerMapping => innerMapping.nn (sym) != null
647
649
648
650
override def registeredTypeMembers (path : PathType ): List [Symbol ] = pathDepMapping(path).nn.keys
649
651
@@ -691,7 +693,7 @@ final class ProperGadtConstraint private(
691
693
692
694
override def resetScrutineePath (): Unit = myScrutineePath = null
693
695
694
- override def withScrutineePath [T ](path : TermRef )(op : => T ): T =
696
+ override def withScrutineePath [T ](path : TermRef | Null )(op : => T ): T =
695
697
val saved = this .myScrutineePath
696
698
this .myScrutineePath = path
697
699
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