[Tests] More conservative stableOrdered dump

Order of enum entries and fields matters, we can't sort them too.

^KT-65460
This commit is contained in:
Pavel Kunyavskiy
2024-02-05 16:45:10 +01:00
committed by Space Team
parent 5d4e822f42
commit 0fa42a9c11
27 changed files with 613 additions and 606 deletions
@@ -75,7 +75,11 @@ private fun IrFile.shouldSkipDump(): Boolean {
/**
* Sorts the declarations in the list using the result of [IrDeclaration.render] as the sorting key.
*
* The exception is properties with backing fields and [IrAnonymousInitializer]s: their relative order is preserved.
* The exceptions for which relative order is preserved as it matters for code generation:
* * Properties with backing field
* * Anonymous initializers
* * Enum entries
* * Fields
*/
internal fun List<IrDeclaration>.stableOrdered(): List<IrDeclaration> {
val strictOrder = hashMapOf<IrDeclaration, Int>()
@@ -83,10 +87,12 @@ internal fun List<IrDeclaration>.stableOrdered(): List<IrDeclaration> {
var idx = 0
forEach {
if (it is IrProperty && it.backingField != null && !it.isConst) {
strictOrder[it] = idx++
val shouldPreserveRelativeOrder = when (it) {
is IrProperty -> it.backingField != null && !it.isConst
is IrAnonymousInitializer, is IrEnumEntry, is IrField -> true
else -> false
}
if (it is IrAnonymousInitializer) {
if (shouldPreserveRelativeOrder) {
strictOrder[it] = idx++
}
}