Skip to content

Commit da5f314

Browse files
committed
Partially fix idempotency of static method order
Some source of nondeterminism remains in the backend.
1 parent 3ec0192 commit da5f314

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class MoveStatics extends MiniPhase with SymTransformer {
3434
override def transformStats(trees: List[Tree])(implicit ctx: Context): List[Tree] = {
3535
if (ctx.owner.is(Flags.Package)) {
3636
val (classes, others) = trees.partition(x => x.isInstanceOf[TypeDef] && x.symbol.isClass)
37-
val pairs = classes.groupBy(_.symbol.name.stripModuleClassSuffix).asInstanceOf[Map[Name, List[TypeDef]]]
37+
// TODO make a groupBy that builds linked maps
38+
val pairs = classes.groupBy(_.symbol.name.stripModuleClassSuffix).asInstanceOf[Map[Name, List[TypeDef]]].toList.sortBy(_._1.toString)
3839

3940
def rebuild(orig: TypeDef, newBody: List[Tree]): Tree = {
4041
if (orig eq null) return EmptyTree
@@ -73,7 +74,7 @@ class MoveStatics extends MiniPhase with SymTransformer {
7374
if (classes.head.symbol.is(Flags.Module)) move(classes.head, null)
7475
else List(rebuild(classes.head, classes.head.rhs.asInstanceOf[Template].body))
7576
else move(classes.head, classes.tail.head)
76-
Trees.flatten(newPairs.toList.flatten ++ others)
77+
Trees.flatten(newPairs.flatten ++ others)
7778
} else trees
7879
}
7980
}

0 commit comments

Comments
 (0)