From 650a3c467d9f9564a1e8e5ce1b75ec7361341e9c Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Mon, 22 May 2023 18:04:56 +0200 Subject: [PATCH] [PL] Fix: Use stable order of return targets in 'illegalNonLocalReturn' case --- .../partial/PartialLinkageErrorMessages.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/linkage/partial/PartialLinkageErrorMessages.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/linkage/partial/PartialLinkageErrorMessages.kt index f58daac1273..bda308bfa94 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/linkage/partial/PartialLinkageErrorMessages.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/linkage/partial/PartialLinkageErrorMessages.kt @@ -277,6 +277,12 @@ private fun Appendable.declarationKindName(symbol: IrSymbol, capitalized: Boolea return append(" ").declarationName(symbol) } +// Note: All items are rendered lower-case. +private fun Appendable.sortedDeclarationsKindName(symbols: Set): Appendable { + symbols.map { symbol -> buildString inner@ { this@inner.declarationKindName(symbol, capitalized = false) } }.sorted().joinTo(this) + return this +} + private fun Appendable.sortedDeclarationsName(symbols: Set): Appendable { symbols.map { symbol -> buildString inner@ { this@inner.declarationName(symbol) } }.sorted().joinTo(this) return this @@ -547,15 +553,11 @@ private fun Appendable.invalidSamConversion( private fun Appendable.suspendableCallWithoutCoroutine(): Appendable = append("Suspend function can be called only from a coroutine or another suspend function") -private fun Appendable.illegalNonLocalReturn(expression: IrReturn, validReturnTargets: Set): Appendable { - append("Illegal non-local return: The return target is ").declarationKindName(expression.returnTargetSymbol, capitalized = false) - append(" while only the following return targets are allowed: ") - validReturnTargets.forEachIndexed { index, returnTarget -> - if (index > 0) append(", ") - declarationKindName(returnTarget, capitalized = false) - } - return this -} +private fun Appendable.illegalNonLocalReturn(expression: IrReturn, validReturnTargets: Set): Appendable = + append("Illegal non-local return: The return target is ") + .declarationKindName(expression.returnTargetSymbol, capitalized = false) + .append(" while only the following return targets are allowed: ") + .sortedDeclarationsKindName(validReturnTargets) private fun Appendable.inaccessibleDeclaration( referencedDeclarationSymbol: IrSymbol,