diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt index ae3f2d8363b..d96b95827b1 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt @@ -74,7 +74,7 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor { override fun visitWhenExpression(expression: IrWhenExpression, data: String) { expression.dumpLabeledElementWith(data) { expression.subject?.let { subject -> - subject.accept(this, "\$subject:") + subject.accept(this, "\$subject") } for (branch in expression.branches) { branch.conditions.forEach { it.accept(this, "if") } diff --git a/compiler/testData/ir/irText/when.kt b/compiler/testData/ir/irText/when.kt index 708c246b507..0f9cfa3bbac 100644 --- a/compiler/testData/ir/irText/when.kt +++ b/compiler/testData/ir/irText/when.kt @@ -1,10 +1,19 @@ object A -fun test(x: Any?) = +fun testWithSubject(x: Any?) = when (x) { null -> "null" A -> "A" is String -> "String" in setOf() -> "nothingness?" else -> "something" - } \ No newline at end of file + } + +fun test(x: Any?) = + when { + x == null -> "null" + x == A -> "A" + x is String -> "String" + x in setOf() -> "nothingness?" + else -> "something" + } diff --git a/compiler/testData/ir/irText/when.txt b/compiler/testData/ir/irText/when.txt index 5b89a06c1d8..8ae91505d9d 100644 --- a/compiler/testData/ir/irText/when.txt +++ b/compiler/testData/ir/irText/when.txt @@ -1,11 +1,11 @@ IrFile /when.kt DUMMY A - IrFunction public fun test(/*0*/ x: kotlin.Any?): kotlin.String + IrFunction public fun testWithSubject(/*0*/ x: kotlin.Any?): kotlin.String IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= WHEN subject=tmp0_subject type=kotlin.String - $subject:: VAR val tmp0_subject: kotlin.Any? + $subject: VAR val tmp0_subject: kotlin.Any? GET_VAR x type=kotlin.Any? operator=null if: BINARY_OP operator=EQEQ type=kotlin.Boolean related=null GET_VAR tmp0_subject type=kotlin.Any? operator=null @@ -24,3 +24,25 @@ IrFile /when.kt GET_VAR tmp0_subject type=kotlin.Any? operator=null then: LITERAL String type=kotlin.String value='nothingness?' else: LITERAL String type=kotlin.String value='something' + IrFunction public fun test(/*0*/ x: kotlin.Any?): kotlin.String + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + WHEN subject=null type=kotlin.String + if: BINARY_OP operator=EQEQ type=kotlin.Boolean related=public open operator fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + GET_VAR x type=kotlin.Any? operator=null + LITERAL Null type=kotlin.Nothing? value='null' + then: LITERAL String type=kotlin.String value='null' + if: BINARY_OP operator=EQEQ type=kotlin.Boolean related=public open operator fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + GET_VAR x type=kotlin.Any? operator=null + GET_OBJECT A type=A + then: LITERAL String type=kotlin.String value='A' + if: TYPE_OP operator=INSTANCEOF typeOperand=kotlin.String + GET_VAR x type=kotlin.Any? operator=null + then: LITERAL String type=kotlin.String value='String' + if: CALL .contains type=kotlin.Boolean operator=IN + $receiver: CALL .setOf type=kotlin.collections.Set operator=null + element: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.Any + GET_VAR x type=kotlin.Any? operator=null + then: LITERAL String type=kotlin.String value='nothingness?' + else: LITERAL String type=kotlin.String value='something'