@@ -121,8 +121,12 @@ trait BCodeSkelBuilder extends BCodeHelpers {
121
121
for (f <- claszSymbol.info.decls.filter(_.isField))
122
122
f.setFlag(JavaStatic )
123
123
124
+ val (clinits, body) = impl.body.partition(stat => stat.isInstanceOf [DefDef ] && stat.symbol.isStaticConstructor)
125
+
124
126
val (uptoSuperStats, remainingConstrStats) = splitAtSuper(impl.constr.rhs.asInstanceOf [Block ].stats)
125
- val clInitSymbol = ctx.newSymbol(
127
+ val clInitSymbol : TermSymbol =
128
+ if (clinits.nonEmpty) clinits.head.symbol.asTerm
129
+ else ctx.newSymbol(
126
130
claszSymbol,
127
131
nme.STATIC_CONSTRUCTOR ,
128
132
JavaStatic | Method ,
@@ -156,17 +160,19 @@ trait BCodeSkelBuilder extends BCodeHelpers {
156
160
val callConstructor = New (claszSymbol.typeRef).select(claszSymbol.primaryConstructor).appliedToArgs(Nil )
157
161
val assignModuleField = Assign (ref(moduleField), callConstructor)
158
162
val remainingConstrStatsSubst = remainingConstrStats.map(rewire)
159
- val clinit = DefDef (
160
- clInitSymbol,
161
- Block (assignModuleField :: remainingConstrStatsSubst, unitLiteral)
162
- )
163
+ val clinit = clinits match {
164
+ case (ddef : DefDef ) :: _ =>
165
+ cpy.DefDef (ddef)(rhs = Block (ddef.rhs :: assignModuleField :: remainingConstrStatsSubst, unitLiteral))
166
+ case _ =>
167
+ DefDef (clInitSymbol, Block (assignModuleField :: remainingConstrStatsSubst, unitLiteral))
168
+ }
163
169
164
170
val constr2 = {
165
171
val rhs = Block (uptoSuperStats, impl.constr.rhs.asInstanceOf [Block ].expr)
166
172
cpy.DefDef (impl.constr)(rhs = rhs)
167
173
}
168
174
169
- val impl2 = cpy.Template (impl)(constr = constr2, body = clinit :: impl. body)
175
+ val impl2 = cpy.Template (impl)(constr = constr2, body = clinit :: body)
170
176
cpy.TypeDef (cd0)(rhs = impl2)
171
177
} else cd0
172
178
0 commit comments