Skip to content

Commit f32eefc

Browse files
committed
-Ytest-pickler: homogenize template body output order
1 parent 13692aa commit f32eefc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,20 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
268268
val selfName = if (self.name == nme.WILDCARD) "this" else self.name.toString
269269
(selfName ~ optText(self.tpt)(": " ~ _) ~ " =>").close
270270
} provided !self.isEmpty
271-
val bodyText = "{" ~~ selfText ~~ toTextGlobal(primaryConstrs ::: impl.body, "\n") ~ "}"
271+
272+
val body = if (ctx.settings.YtestPickler.value) {
273+
// Pickling/unpickling reorders the body members, so we need to homogenize
274+
val (params, rest) = impl.body partition {
275+
case stat: TypeDef => stat.symbol.is(Param)
276+
case stat: ValOrDefDef =>
277+
stat.symbol.is(ParamAccessor) && !stat.symbol.isSetter
278+
case _ => false
279+
}
280+
params ::: rest
281+
} else impl.body
282+
283+
val bodyText = "{" ~~ selfText ~~ toTextGlobal(primaryConstrs ::: body, "\n") ~ "}"
284+
272285
prefix ~ (" extends" provided !ofNew) ~~ parentsText ~~ bodyText
273286
}
274287

0 commit comments

Comments
 (0)