From ab0e734e7d481db87aae80c2ee3b8825a21b663b Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 12 Jul 2017 12:30:23 +0300 Subject: [PATCH] PseudocodeLabel: add slightly better exception diagnostics --- .../kotlin/cfg/pseudocode/PseudocodeLabel.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/PseudocodeLabel.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/PseudocodeLabel.kt index 9bea6ad66eb..bab6e53952d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/PseudocodeLabel.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/PseudocodeLabel.kt @@ -34,11 +34,16 @@ class PseudocodeLabel internal constructor( override fun resolveToInstruction(): Instruction { val index = targetInstructionIndex - if (index < 0 || index >= instructionList.size) { - error("resolveToInstruction: incorrect index $index for label $name " + - "in subroutine ${correspondingElement.text} with instructions $instructionList") + when { + index < 0 -> + error("resolveToInstruction: unbound label $name " + + "in subroutine ${correspondingElement.text} with instructions $instructionList") + index >= instructionList.size -> + error("resolveToInstruction: incorrect index $index for label $name " + + "in subroutine ${correspondingElement.text} with instructions $instructionList") + else -> + return instructionList[index] } - return instructionList[index] } fun copy(newPseudocode: PseudocodeImpl, newLabelIndex: Int): PseudocodeLabel =