Skip to content

Commit 972300b

Browse files
committed
Don't specialize abstract apply
1 parent cdfe18a commit 972300b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
4141

4242
val apply = baseType.member(nme.apply)
4343
val overrideApply = tp.decls.find { sym =>
44-
sym.is(Flags.Method) && sym.name == nme.apply && sym.info.matches(apply.info)
44+
sym.is(Flags.Method, butNot = Flags.Deferred) && sym.name == nme.apply && sym.info.matches(apply.info)
4545
}
4646

4747
def isSpecializable = defn.isSpecializableFunction(sym.asClass, argTypes, retType)

compiler/test/dotty/tools/dotc/transform/SpecializeFunctionsTests.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ class SpecializeFunctionsTests extends DottyBytecodeTest {
6767
}
6868
}
6969

70+
@Test def notSpecializeAbstractMethod = {
71+
val source =
72+
"""|trait Vector extends (Int=>Int) {
73+
| override def apply(i: Int): Int
74+
|}""".stripMargin
75+
76+
checkBCode(source) { dir =>
77+
val apps =
78+
findClass("Vector", dir).methods.asScala.collect {
79+
case m if m.name == "apply$mcII$sp" => m
80+
case m if m.name == "apply" => m
81+
}
82+
.map(_.name)
83+
.toList
84+
85+
assert(
86+
apps.length == 1,
87+
s"Wrong number of specialized applys, actual length: ${apps.length} - $apps"
88+
)
89+
}
90+
}
91+
7092
@Test def noBoxingSpecFunction0 = {
7193
implicit val source: String =
7294
"""|class Test {

0 commit comments

Comments
 (0)