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