@@ -75,6 +75,28 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
75
75
def transformType (tp : Type , inferred : Boolean )(using Context ): Type = tp
76
76
77
77
object transformTypes extends TreeTraverser :
78
+
79
+ class SubstParams (from : List [Symbol ], to : MethodOrPoly )(using Context )
80
+ extends DeepTypeMap , BiTypeMap :
81
+ private val paramRefs = to.paramRefs
82
+ private val fromRefs = from.map(_.namedType)
83
+
84
+ def apply (t : Type ): Type = t match
85
+ case t : NamedType =>
86
+ val sym = t.symbol
87
+ def recur (from : List [Symbol ], to : List [Type ]): Type =
88
+ if from.isEmpty then t
89
+ else if sym eq from.head then to.head
90
+ else recur(from.tail, to.tail)
91
+ recur(from, paramRefs)
92
+ case _ =>
93
+ mapOver(t)
94
+
95
+ def inverse (t : Type ): Type = t match
96
+ case t : ParamRef if t.binder eq to => fromRefs(t.paramNum)
97
+ case _ => mapOver(t)
98
+ end SubstParams
99
+
78
100
def traverse (tree : Tree )(using Context ) =
79
101
traverseChildren(tree)
80
102
tree match
@@ -85,7 +107,7 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
85
107
def integrateRT (restp : Type , info : Type , psymss : List [List [Symbol ]]): Type = info match
86
108
case info : MethodOrPoly =>
87
109
info.derivedLambdaType(resType =
88
- integrateRT(restp.subst (psymss.head, info.paramRefs ), info.resType, psymss.tail))
110
+ integrateRT(SubstParams (psymss.head, info)(restp ), info.resType, psymss.tail))
89
111
case info : ExprType =>
90
112
info.derivedExprType(resType = restp)
91
113
case _ =>
0 commit comments