Skip to content

Commit 194fac7

Browse files
committed
Make instantiteRT a BiTypeMap
Otherwise we will not be able to do upper approximations of parameters.
1 parent a585961 commit 194fac7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

compiler/src/dotty/tools/dotc/transform/Recheck.scala

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
7575
def transformType(tp: Type, inferred: Boolean)(using Context): Type = tp
7676

7777
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+
78100
def traverse(tree: Tree)(using Context) =
79101
traverseChildren(tree)
80102
tree match
@@ -85,7 +107,7 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
85107
def integrateRT(restp: Type, info: Type, psymss: List[List[Symbol]]): Type = info match
86108
case info: MethodOrPoly =>
87109
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))
89111
case info: ExprType =>
90112
info.derivedExprType(resType = restp)
91113
case _ =>

0 commit comments

Comments
 (0)