Skip to content

Commit 1801a1f

Browse files
committed
Don't remove parents not being specialized
1 parent 6f0a85e commit 1801a1f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
105105
ctx.requiredClassRef(functionPkg ++ specializedName(functionName ++ arity, args, ret))
106106
}
107107
val specializedMethodName = specializedName(nme.apply, args, ret)
108-
val specializedApply = ctx.owner.info.decls.lookup(specializedMethodName).asTerm
108+
val specializedApply = ctx.owner.info.decls.lookup(specializedMethodName)
109109

110-
orig -> (specializedParent, specializedApply)
111-
}).toMap
110+
if (specializedApply.exists)
111+
Some(orig -> (specializedParent, specializedApply.asTerm))
112+
else None
113+
}).flatten.toMap
112114

113115
val body0 = tmpl.body.foldRight(List.empty[Tree]) {
114116
case (tree: DefDef, acc) if tree.name == nme.apply => {
@@ -140,9 +142,15 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
140142
}
141143
case (tree, acc) => tree :: acc
142144
}
143-
val parents = symbolMap.map { case (_, (parent, _)) => parent }
144145

145-
cpy.Template(tmpl)(parents = parents.toList, body = body0)
146+
val specializedParents = tree.parents.map { t =>
147+
symbolMap
148+
.get(t.symbol)
149+
.map { case (newSym, _) => newSym }
150+
.getOrElse(t)
151+
}
152+
153+
cpy.Template(tmpl)(parents = specializedParents, body = body0)
146154
}
147155
case _ => tree
148156
}

0 commit comments

Comments
 (0)