Skip to content

Commit 787d040

Browse files
committed
Fix bootstrap exception
1 parent adaa2c1 commit 787d040

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
1818

1919
/** Transforms the type to include decls for specialized applys */
2020
override def transformInfo(tp: Type, sym: Symbol)(using Context) = tp match {
21-
case tp: ClassInfo if !sym.is(Flags.Package) && derivesFromFn012(sym) =>
21+
case tp: ClassInfo if !sym.is(Flags.Package) =>
2222
val newApplys = new mutable.ListBuffer[Symbol]
2323

2424
var arity = 0
2525
while (arity < 3) {
2626
val func = defn.FunctionClass(arity)
2727
if (tp.derivesFrom(func)) {
28-
val paramTypes = tp.cls.typeRef.baseType(func).argInfos
29-
val isSpecializable =
28+
lazy val paramTypes = tp.cls.typeRef.baseType(func).argInfos
29+
def isSpecializable =
3030
defn.isSpecializableFunction(
3131
sym.asClass,
3232
paramTypes.init,
3333
paramTypes.last
3434
)
3535

3636
val apply = tp.decls.lookup(nme.apply)
37-
if (isSpecializable && apply.exists) {
37+
if (apply.exists && isSpecializable) {
3838
val specializedMethodName = specializedName(nme.apply, paramTypes)
3939
val applySpecialized = newSymbol(
4040
sym,
@@ -70,7 +70,11 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
7070

7171
val applyBuf = new mutable.ListBuffer[Tree]
7272
val newBody = tree.body.mapConserve {
73-
case ddef: DefDef if ddef.name == nme.apply && ddef.vparamss.length == 1 =>
73+
case ddef: DefDef
74+
if ddef.name == nme.apply &&
75+
ddef.vparamss.length == 1 &&
76+
ddef.vparamss.head.length < 3
77+
=>
7478
val paramTypes = ddef.vparamss.head.map(_.symbol.info)
7579
val retType = ddef.tpe.widen.finalResultType
7680

@@ -94,7 +98,8 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
9498
case x => x
9599
}
96100

97-
cpy.Template(tree)(body = applyBuf.toList ::: newBody)
101+
if applyBuf.isEmpty then tree
102+
else cpy.Template(tree)(body = applyBuf.toList ::: newBody)
98103
}
99104

100105
/** Dispatch to specialized `apply`s in user code when available */

0 commit comments

Comments
 (0)