Skip to content

Commit cdfe18a

Browse files
committed
Handle abstract apply and multiple applys
1 parent e7657aa commit cdfe18a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,25 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
3434
while (arity < 3) {
3535
val func = defn.FunctionClass(arity)
3636
if (sym.derivesFrom(func)) {
37-
val baseType = tp.cls.typeRef.baseType(func)
38-
val apply = baseType.member(nme.apply)
39-
37+
val baseType = tp.cls.typeRef.baseType(func)
4038
val paramTypes = baseType.argInfos
41-
val argTypes = paramTypes.init
42-
val retType = paramTypes.last
39+
val argTypes = paramTypes.init
40+
val retType = paramTypes.last
41+
42+
val apply = baseType.member(nme.apply)
43+
val overrideApply = tp.decls.find { sym =>
44+
sym.is(Flags.Method) && sym.name == nme.apply && sym.info.matches(apply.info)
45+
}
4346

44-
val isSpecializable = defn.isSpecializableFunction(sym.asClass, argTypes, retType)
47+
def isSpecializable = defn.isSpecializableFunction(sym.asClass, argTypes, retType)
4548

46-
if (isSpecializable) {
49+
if (overrideApply.exists && isSpecializable) {
4750
val specializedMethodName: Name = nme.apply.specializedFunction(retType, argTypes)
4851
val applySpecialized = newSymbol(
4952
sym,
5053
specializedMethodName,
51-
Flags.Override | Flags.Method | Flags.Synthetic,
52-
apply.info
54+
overrideApply.flags | Flags.Synthetic,
55+
overrideApply.info
5356
)
5457

5558
newApplys += applySpecialized

0 commit comments

Comments
 (0)