@@ -105,10 +105,7 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
105105 /** Dispatch to specialized `apply`s in user code when available */
106106 override def transformApply (tree : Apply )(using Context ) =
107107 tree match {
108- case Apply (fun, args)
109- if fun.symbol.name == nme.apply &&
110- derivesFromFn012(fun.symbol.owner)
111- =>
108+ case Apply (fun, args) if fun.symbol.name == nme.apply =>
112109 val paramTypes = (fun.tpe.widen.firstParamTypes :+ tree.tpe).map(_.widenSingleton.dealias)
113110 val isSpecializable =
114111 defn.isSpecializableFunction(
@@ -117,23 +114,22 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
117114 paramTypes.last
118115 )
119116
120- if (isSpecializable && ! paramTypes.exists(_.isInstanceOf [ExprType ])) {
121- val specializedApply = specializedName(nme.apply, paramTypes)
122- val newSel = fun match {
123- case Select (qual, _) =>
124- qual.select(specializedApply)
125- case _ =>
126- (fun.tpe: @ unchecked) match {
127- case TermRef (prefix : ThisType , name) =>
128- tpd.This (prefix.cls).select(specializedApply)
129- case TermRef (prefix : NamedType , name) =>
130- tpd.ref(prefix).select(specializedApply)
131- }
132- }
133-
134- newSel.appliedToArgs(args)
117+ if (! isSpecializable || paramTypes.exists(_.isInstanceOf [ExprType ])) return tree
118+
119+ val specializedApply = specializedName(nme.apply, paramTypes)
120+ val newSel = fun match {
121+ case Select (qual, _) =>
122+ qual.select(specializedApply)
123+ case _ =>
124+ (fun.tpe: @ unchecked) match {
125+ case TermRef (prefix : ThisType , name) =>
126+ tpd.This (prefix.cls).select(specializedApply)
127+ case TermRef (prefix : NamedType , name) =>
128+ tpd.ref(prefix).select(specializedApply)
129+ }
135130 }
136- else tree
131+
132+ newSel.appliedToArgs(args)
137133
138134 case _ => tree
139135 }
0 commit comments