More tests for 'when'
This commit is contained in:
committed by
Dmitry Petrov
parent
b96626fd4c
commit
de5181d642
@@ -74,7 +74,7 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
|
|||||||
override fun visitWhenExpression(expression: IrWhenExpression, data: String) {
|
override fun visitWhenExpression(expression: IrWhenExpression, data: String) {
|
||||||
expression.dumpLabeledElementWith(data) {
|
expression.dumpLabeledElementWith(data) {
|
||||||
expression.subject?.let { subject ->
|
expression.subject?.let { subject ->
|
||||||
subject.accept(this, "\$subject:")
|
subject.accept(this, "\$subject")
|
||||||
}
|
}
|
||||||
for (branch in expression.branches) {
|
for (branch in expression.branches) {
|
||||||
branch.conditions.forEach { it.accept(this, "if") }
|
branch.conditions.forEach { it.accept(this, "if") }
|
||||||
|
|||||||
Vendored
+11
-2
@@ -1,10 +1,19 @@
|
|||||||
object A
|
object A
|
||||||
|
|
||||||
fun test(x: Any?) =
|
fun testWithSubject(x: Any?) =
|
||||||
when (x) {
|
when (x) {
|
||||||
null -> "null"
|
null -> "null"
|
||||||
A -> "A"
|
A -> "A"
|
||||||
is String -> "String"
|
is String -> "String"
|
||||||
in setOf<Nothing>() -> "nothingness?"
|
in setOf<Nothing>() -> "nothingness?"
|
||||||
else -> "something"
|
else -> "something"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun test(x: Any?) =
|
||||||
|
when {
|
||||||
|
x == null -> "null"
|
||||||
|
x == A -> "A"
|
||||||
|
x is String -> "String"
|
||||||
|
x in setOf<Nothing>() -> "nothingness?"
|
||||||
|
else -> "something"
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+24
-2
@@ -1,11 +1,11 @@
|
|||||||
IrFile /when.kt
|
IrFile /when.kt
|
||||||
DUMMY A
|
DUMMY A
|
||||||
IrFunction public fun test(/*0*/ x: kotlin.Any?): kotlin.String
|
IrFunction public fun testWithSubject(/*0*/ x: kotlin.Any?): kotlin.String
|
||||||
IrExpressionBody
|
IrExpressionBody
|
||||||
BLOCK type=<no-type> hasResult=false operator=null
|
BLOCK type=<no-type> hasResult=false operator=null
|
||||||
RETURN type=<no-type>
|
RETURN type=<no-type>
|
||||||
WHEN subject=tmp0_subject type=kotlin.String
|
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
|
GET_VAR x type=kotlin.Any? operator=null
|
||||||
if: BINARY_OP operator=EQEQ type=kotlin.Boolean related=null
|
if: BINARY_OP operator=EQEQ type=kotlin.Boolean related=null
|
||||||
GET_VAR tmp0_subject type=kotlin.Any? operator=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
|
GET_VAR tmp0_subject type=kotlin.Any? operator=null
|
||||||
then: LITERAL String type=kotlin.String value='nothingness?'
|
then: LITERAL String type=kotlin.String value='nothingness?'
|
||||||
else: LITERAL String type=kotlin.String value='something'
|
else: LITERAL String type=kotlin.String value='something'
|
||||||
|
IrFunction public fun test(/*0*/ x: kotlin.Any?): kotlin.String
|
||||||
|
IrExpressionBody
|
||||||
|
BLOCK type=<no-type> hasResult=false operator=null
|
||||||
|
RETURN type=<no-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<kotlin.Nothing> 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'
|
||||||
|
|||||||
Reference in New Issue
Block a user