Skip to content

Commit 95ad5ab

Browse files
committed
Fix proper forwarding in definition body
1 parent 7ab2842 commit 95ad5ab

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
4646
*/
4747
def transform(ref: SingleDenotation)(implicit ctx: Context) = ref match {
4848
case cref @ ShouldTransformDenot(targets) => {
49-
ctx.echo(s"Transforming denot $cref...")
5049
val specializedSymbols: Map[Symbol, (Symbol, Symbol)] = (for (SpecializationTarget(target, args, ret, original) <- targets) yield {
5150
val arity = args.length
5251
val specializedParent = ctx.getClassIfDefined {
@@ -69,7 +68,6 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
6968
def specializeApplys(scope: Scope): Scope = {
7069
val alteredScope = scope.cloneScope
7170
specializedSymbols.values.foreach { case (_, apply) =>
72-
println(s"entering: $apply")
7371
alteredScope.enter(apply)
7472
}
7573
alteredScope
@@ -112,9 +110,17 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
112110
orig -> (specializedParent, specializedApply)
113111
}).toMap
114112

115-
val body = tmpl.body.foldRight(List.empty[Tree]) {
113+
val body0 = tmpl.body.foldRight(List.empty[Tree]) {
116114
case (tree: DefDef, acc) if tree.name == nme.apply => {
117-
symbolMap.get(tree.symbol).map { case (parent, apply) =>
115+
val inheritedFrom =
116+
tree.symbol.allOverriddenSymbols
117+
.map(_.owner)
118+
.map(symbolMap.get)
119+
.flatten
120+
.toList
121+
.headOption
122+
123+
inheritedFrom.map { case (parent, apply) =>
118124
val forwardingBody = tpd
119125
.ref(apply)
120126
.appliedToArgs(tree.vparamss.head.map(vparam => ref(vparam.symbol)))
@@ -136,7 +142,7 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
136142
}
137143
val parents = symbolMap.map { case (_, (parent, _)) => parent }
138144

139-
cpy.Template(tmpl)(parents = parents.toList, body = body)
145+
cpy.Template(tmpl)(parents = parents.toList, body = body0)
140146
}
141147
case _ => tree
142148
}

0 commit comments

Comments
 (0)