@@ -7,7 +7,7 @@ package scala.tools.nsc
7
7
package transform
8
8
9
9
import symtab ._
10
- import Flags ._
10
+ import reflect . internal . Flags ._
11
11
import scala .collection .{ mutable , immutable }
12
12
13
13
abstract class Mixin extends InfoTransform with ast.TreeDSL {
@@ -1060,6 +1060,21 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
1060
1060
isOverriddenAccessor(other.getterIn(other.owner), clazz.info.baseClasses)
1061
1061
}
1062
1062
1063
+ if (isFunctionSymbol(clazz) && clazz.isSpecialized) {
1064
+ val sym = clazz.info.decl(nme.apply)
1065
+ // <default> def apply(v1: Object)Object = apply(v1.unbox).box
1066
+ val functionClass = clazz.baseClasses(1 )
1067
+ val genericApply = functionClass.info.member(nme.apply)
1068
+ val bridge = genericApply.cloneSymbol(clazz, /* BRIDGE |*/ METHOD | DEFAULTMETHOD | DEFERRED ).setPos(sym.pos)
1069
+ addDefDef(bridge,
1070
+ Apply (gen.mkAttributedSelect(gen.mkAttributedThis(sym.owner), sym), bridge.paramss.head.map(p => gen.mkAttributedIdent(p))))
1071
+
1072
+ // <deferred> def apply$mcII$sp(v1: Int)Int
1073
+ val specializedApply = specializeTypes.specializedOverloaded(genericApply, exitingSpecialize(clazz.info.baseType(functionClass).typeArgs))
1074
+ val m2 = specializedApply.cloneSymbol(clazz, METHOD | DEFERRED ).setPos(sym.pos)
1075
+ addDefDef(m2.setPos(sym.pos))
1076
+ }
1077
+
1063
1078
// for all symbols `sym` in the class definition, which are mixed in:
1064
1079
for (sym <- clazz.info.decls ; if sym hasFlag MIXEDIN ) {
1065
1080
// if current class is a trait interface, add an abstract method for accessor `sym`
@@ -1167,6 +1182,26 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
1167
1182
case Apply (TypeApply (Select (qual, _), targ :: _), _) if isCastSymbol(sym) && (qual.tpe <:< targ.tpe) =>
1168
1183
qual
1169
1184
1185
+ case dd @ DefDef (_, _, _, vparamss, _, EmptyTree ) if isFunctionSymbol(sym.owner) =>
1186
+ val addDefault = enteringPhase(currentRun.erasurePhase.prev)(! sym.isDeferred) && sym.name != nme.toString_ // before lateDEFERRED
1187
+ if (addDefault) {
1188
+ def implSym = implClass(sym.owner).info.member(sym.name)
1189
+ sym.setFlag(Flags .DEFAULTMETHOD )
1190
+ val tree = Apply (staticRef(implSym), gen.mkAttributedThis(sym.owner) :: sym.paramss.head.map(gen.mkAttributedRef))
1191
+ val app = typedPos(tree.pos)(tree)
1192
+ copyDefDef(dd)(rhs = app)
1193
+ } else if (sym.owner.isSpecialized && sym.name == nme.apply) {
1194
+ val clazz = sym.owner
1195
+ val functionClass = clazz.baseClasses(1 )
1196
+ val substitutedApply = clazz.info.decl(nme.apply)
1197
+ val genericApply = functionClass.info.decl(nme.apply)
1198
+ val specializedApply = specializeTypes.specializedOverloaded(genericApply, exitingSpecialize(clazz.info.baseType(functionClass).typeArgs))
1199
+ val app = Apply (gen.mkAttributedSelect(gen.mkAttributedThis(clazz), specializedApply), vparamss.head.map(p => gen.mkAttributedIdent(p.symbol)))
1200
+ dd.symbol.flags = dd.symbol.flags | Flags .DEFAULTMETHOD
1201
+ copyDefDef(dd)(rhs = typedPos(tree.pos)(app))
1202
+ } else {
1203
+ tree
1204
+ }
1170
1205
case Apply (Select (qual, _), args) =>
1171
1206
/* Changes `qual.m(args)` where m refers to an implementation
1172
1207
* class method to Q.m(S, args) where Q is the implementation module of
0 commit comments