@@ -20,29 +20,28 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
20
20
! ctx.settings.scalajs.value
21
21
22
22
override def infoMayChange (sym : Symbol )(using Context ): Boolean =
23
- ! sym.is(Flags .Package ) && sym.isDefinedInCurrentRun
23
+ ! sym.is(Flags .Package ) && sym.isClass && sym. isDefinedInCurrentRun
24
24
25
25
/** Transforms the type to include decls for specialized applys */
26
26
override def transformInfo (tp : Type , sym : Symbol )(using Context ) = tp match {
27
27
case tp : ClassInfo =>
28
28
val newApplys = new mutable.ListBuffer [Symbol ]
29
+ val apply = tp.decls.lookup(nme.apply)
30
+
31
+ if (! apply.exists) return tp
29
32
30
33
var arity = 0
31
34
while (arity < 3 ) {
32
35
val func = defn.FunctionClass (arity)
33
36
if (tp.derivesFrom(func)) {
34
- var specializedMethodName : Name = null
35
- def isSpecializable =
36
- val paramTypes = tp.cls.typeRef.baseType(func).argInfos
37
- val argTypes = paramTypes.init
38
- val retType = paramTypes.last
39
- defn.isSpecializableFunction(sym.asClass, argTypes, retType) && {
40
- specializedMethodName = nme.apply.specializedFunction(retType, argTypes)
41
- true
42
- }
37
+ val paramTypes = tp.cls.typeRef.baseType(func).argInfos
38
+ val argTypes = paramTypes.init
39
+ val retType = paramTypes.last
40
+
41
+ val isSpecializable = defn.isSpecializableFunction(sym.asClass, argTypes, retType)
43
42
44
- val apply = tp.decls.lookup(nme.apply)
45
- if ( apply.exists && isSpecializable) {
43
+ if (isSpecializable) {
44
+ val specializedMethodName : Name = nme. apply.specializedFunction(retType, argTypes)
46
45
val applySpecialized = newSymbol(
47
46
sym,
48
47
specializedMethodName,
@@ -71,7 +70,7 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
71
70
* in the template body.
72
71
*/
73
72
override def transformTemplate (tree : Template )(using Context ) = {
74
- val cls = tree.symbol.enclosingClass .asClass
73
+ val cls = tree.symbol.owner .asClass
75
74
76
75
if (! derivesFromFn012(cls)) return tree
77
76
0 commit comments