@@ -73,6 +73,12 @@ sealed abstract class GadtConstraint extends Showable {
73
73
/** Set the scrutinee path. */
74
74
def withScrutineePath [T ](path : TermRef | Null )(op : => T ): T
75
75
76
+ /** Supply the real pattern path. */
77
+ def supplyPatternPath (path : TermRef )(using Context ): Unit
78
+
79
+ /** Create a skolem type for pattern. */
80
+ def createPatternSkolem (pat : Type ): SkolemType
81
+
76
82
/** Is the symbol registered in the constraint?
77
83
*
78
84
* @note this is true even if the symbol is constrained to be equal to another type, unlike [[Constraint.contains ]].
@@ -114,7 +120,8 @@ final class ProperGadtConstraint private(
114
120
private var pathDepReverseMapping : SimpleIdentityMap [TypeParamRef , TypeRef ],
115
121
private var wasConstrained : Boolean ,
116
122
private var myScrutineePath : TermRef | Null ,
117
- private var myUnionFind : SimpleIdentityMap [PathType , PathType ]
123
+ private var myUnionFind : SimpleIdentityMap [PathType , PathType ],
124
+ private var myPatternSkolem : SkolemType | Null ,
118
125
) extends GadtConstraint with ConstraintHandling {
119
126
import dotty .tools .dotc .config .Printers .{gadts , gadtsConstr }
120
127
@@ -126,7 +133,8 @@ final class ProperGadtConstraint private(
126
133
pathDepReverseMapping = SimpleIdentityMap .empty,
127
134
wasConstrained = false ,
128
135
myScrutineePath = null ,
129
- myUnionFind = SimpleIdentityMap .empty
136
+ myUnionFind = SimpleIdentityMap .empty,
137
+ myPatternSkolem = null ,
130
138
)
131
139
132
140
// /** Exposes ConstraintHandling.subsumes */
@@ -672,7 +680,8 @@ final class ProperGadtConstraint private(
672
680
pathDepReverseMapping,
673
681
wasConstrained,
674
682
myScrutineePath,
675
- myUnionFind
683
+ myUnionFind,
684
+ myPatternSkolem,
676
685
)
677
686
678
687
def restore (other : GadtConstraint ): Unit = other match {
@@ -685,17 +694,40 @@ final class ProperGadtConstraint private(
685
694
this .wasConstrained = other.wasConstrained
686
695
this .myScrutineePath = other.myScrutineePath
687
696
this .myUnionFind = other.myUnionFind
697
+ this .myPatternSkolem = other.myPatternSkolem
688
698
case _ => ;
689
699
}
690
700
691
701
override def scrutineePath : TermRef | Null = myScrutineePath
692
702
693
703
override def resetScrutineePath (): Unit = myScrutineePath = null
694
704
705
+ override def supplyPatternPath (path : TermRef )(using Context ): Unit =
706
+ if myPatternSkolem eq null then
707
+ ()
708
+ else
709
+ pathDepMapping(myPatternSkolem.nn) match {
710
+ case null =>
711
+ case m : SimpleIdentityMap [Symbol , TypeVar ] =>
712
+ pathDepMapping = pathDepMapping.updated(path, m)
713
+ m foreachBinding { (sym, tvar) =>
714
+ val tpr = tvar.origin
715
+ pathDepReverseMapping = pathDepReverseMapping.updated(tpr, TypeRef (path, sym))
716
+ }
717
+ }
718
+ end supplyPatternPath
719
+
720
+ override def createPatternSkolem (pat : Type ): SkolemType =
721
+ myPatternSkolem = SkolemType (pat)
722
+ myPatternSkolem.nn
723
+ end createPatternSkolem
724
+
695
725
override def withScrutineePath [T ](path : TermRef | Null )(op : => T ): T =
696
726
val saved = this .myScrutineePath
697
727
this .myScrutineePath = path
728
+
698
729
val result = op
730
+
699
731
this .myScrutineePath = saved
700
732
result
701
733
@@ -827,6 +859,10 @@ final class ProperGadtConstraint private(
827
859
828
860
override def withScrutineePath [T ](path : TermRef | Null )(op : => T ): T = op
829
861
862
+ override def supplyPatternPath (path : TermRef )(using Context ): Unit = ()
863
+
864
+ override def createPatternSkolem (pat : Type ): SkolemType = unsupported(" EmptyGadtConstraint.createPatternSkolem" )
865
+
830
866
override def fresh = new ProperGadtConstraint
831
867
override def restore (other : GadtConstraint ): Unit =
832
868
assert(! other.isNarrowing, " cannot restore a non-empty GADTMap" )
0 commit comments