Make 'when' great again.

This commit is contained in:
Dmitry Petrov
2016-08-22 14:17:24 +03:00
committed by Dmitry Petrov
parent f787f8ecbf
commit 97593fa19e
15 changed files with 213 additions and 132 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ IrFile /booleanOperators.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
IF type=kotlin.Boolean operator=ANDAND
WHEN type=kotlin.Boolean operator=ANDAND
if: GET_VAR a type=kotlin.Boolean operator=null
then: GET_VAR b type=kotlin.Boolean operator=null
else: LITERAL Boolean type=kotlin.Boolean value='false'
@@ -11,7 +11,7 @@ IrFile /booleanOperators.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
IF type=kotlin.Boolean operator=OROR
WHEN type=kotlin.Boolean operator=OROR
if: GET_VAR a type=kotlin.Boolean operator=null
then: LITERAL Boolean type=kotlin.Boolean value='true'
else: GET_VAR b type=kotlin.Boolean operator=null
+2 -2
View File
@@ -12,12 +12,12 @@ IrFile /elvis.kt
IrFunction public fun test3(/*0*/ a: kotlin.Any?, /*1*/ b: kotlin.Any?): kotlin.String
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
IF type=kotlin.Unit operator=IF
WHEN type=kotlin.Unit operator=IF
if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=kotlin.String
GET_VAR b type=kotlin.Any? operator=null
then: RETURN type=<no-type>
LITERAL String type=kotlin.String value=''
IF type=kotlin.Unit operator=IF
WHEN type=kotlin.Unit operator=IF
if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=kotlin.String?
GET_VAR a type=kotlin.Any? operator=null
then: RETURN type=<no-type>
+7 -8
View File
@@ -3,16 +3,15 @@ IrFile /ifElseIf.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
IF type=kotlin.Int operator=IF
WHEN type=kotlin.Int operator=WHEN
if: CALL .GT0 type=kotlin.Boolean operator=GT
arg0: CALL .compareTo type=kotlin.Int operator=GT
$this: GET_VAR i type=kotlin.Int operator=null
other: LITERAL Int type=kotlin.Int value='0'
then: LITERAL Int type=kotlin.Int value='1'
else: IF type=kotlin.Int operator=IF
if: CALL .LT0 type=kotlin.Boolean operator=LT
arg0: CALL .compareTo type=kotlin.Int operator=LT
$this: GET_VAR i type=kotlin.Int operator=null
other: LITERAL Int type=kotlin.Int value='0'
then: DUMMY MINUS type=kotlin.Int
else: LITERAL Int type=kotlin.Int value='0'
if: CALL .GT0 type=kotlin.Boolean operator=GT
arg0: CALL .compareTo type=kotlin.Int operator=GT
$this: GET_VAR i type=kotlin.Int operator=null
other: LITERAL Int type=kotlin.Int value='0'
then: LITERAL Int type=kotlin.Int value='1'
else: LITERAL Int type=kotlin.Int value='0'
+3 -3
View File
@@ -18,7 +18,7 @@ IrFile /smartCasts.kt
IrFunction public fun test1(/*0*/ x: kotlin.Any): kotlin.Unit
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
IF type=kotlin.Unit operator=IF
WHEN type=kotlin.Unit operator=IF
if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=kotlin.String
GET_VAR x type=kotlin.Any operator=null
then: RETURN type=<no-type>
@@ -40,7 +40,7 @@ IrFile /smartCasts.kt
IrFunction public fun test2(/*0*/ x: kotlin.Any): kotlin.String
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
IF type=kotlin.Unit operator=IF
WHEN type=kotlin.Unit operator=IF
if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=kotlin.String
GET_VAR x type=kotlin.Any operator=null
then: RETURN type=<no-type>
@@ -52,7 +52,7 @@ IrFile /smartCasts.kt
IrFunction public fun test3(/*0*/ x: kotlin.Any): kotlin.String
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
IF type=kotlin.Unit operator=IF
WHEN type=kotlin.Unit operator=IF
if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=kotlin.String
GET_VAR x type=kotlin.Any operator=null
then: RETURN type=<no-type>
@@ -14,7 +14,7 @@ IrFile /smartCastsWithDestructuring.kt
IrFunction public fun test(/*0*/ x: I1): kotlin.Unit
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
IF type=kotlin.Unit operator=IF
WHEN type=kotlin.Unit operator=IF
if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=I2
GET_VAR x type=I1 operator=null
then: RETURN type=<no-type>
+53 -61
View File
@@ -7,52 +7,46 @@ IrFile /when.kt
BLOCK type=kotlin.String hasResult=true operator=WHEN
VAR val tmp0_subject: kotlin.Any?
GET_VAR x type=kotlin.Any? operator=null
IF type=kotlin.String operator=WHEN
WHEN type=kotlin.String operator=WHEN
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Any? operator=null
arg1: LITERAL Null type=kotlin.Nothing? value='null'
then: LITERAL String type=kotlin.String value='null'
else: IF type=kotlin.String operator=WHEN
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Any? operator=null
arg1: GET_OBJECT A type=A
then: LITERAL String type=kotlin.String value='A'
else: IF type=kotlin.String operator=WHEN
if: TYPE_OP operator=INSTANCEOF typeOperand=kotlin.String
GET_VAR tmp0_subject type=kotlin.Any? operator=null
then: LITERAL String type=kotlin.String value='String'
else: IF type=kotlin.String operator=WHEN
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 tmp0_subject type=kotlin.Any? operator=null
then: LITERAL String type=kotlin.String value='nothingness?'
else: LITERAL String type=kotlin.String value='something'
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Any? operator=null
arg1: GET_OBJECT A type=A
then: LITERAL String type=kotlin.String value='A'
if: TYPE_OP operator=INSTANCEOF typeOperand=kotlin.String
GET_VAR tmp0_subject 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 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=<no-type> hasResult=false operator=null
RETURN type=<no-type>
IF type=kotlin.String operator=WHEN
WHEN type=kotlin.String operator=WHEN
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR x type=kotlin.Any? operator=null
arg1: LITERAL Null type=kotlin.Nothing? value='null'
then: LITERAL String type=kotlin.String value='null'
else: IF type=kotlin.String operator=WHEN
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR x type=kotlin.Any? operator=null
arg1: GET_OBJECT A type=A
then: LITERAL String type=kotlin.String value='A'
else: IF type=kotlin.String operator=WHEN
if: TYPE_OP operator=INSTANCEOF typeOperand=kotlin.String
GET_VAR x type=kotlin.Any? operator=null
then: LITERAL String type=kotlin.String value='String'
else: IF type=kotlin.String operator=WHEN
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'
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR x type=kotlin.Any? operator=null
arg1: 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'
IrFunction public fun testComma(/*0*/ x: kotlin.Int): kotlin.String
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
@@ -60,10 +54,10 @@ IrFile /when.kt
BLOCK type=kotlin.String hasResult=true operator=WHEN
VAR val tmp0_subject: kotlin.Int
GET_VAR x type=kotlin.Int operator=null
IF type=kotlin.String operator=WHEN
if: IF type=kotlin.Boolean operator=WHEN_COMMA
if: IF type=kotlin.Boolean operator=WHEN_COMMA
if: IF type=kotlin.Boolean operator=WHEN_COMMA
WHEN type=kotlin.String operator=WHEN
if: WHEN type=kotlin.Boolean operator=WHEN_COMMA
if: WHEN type=kotlin.Boolean operator=WHEN_COMMA
if: WHEN type=kotlin.Boolean operator=WHEN_COMMA
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='1'
@@ -80,29 +74,27 @@ IrFile /when.kt
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='4'
then: LITERAL String type=kotlin.String value='1234'
else: IF type=kotlin.String operator=WHEN
if: IF type=kotlin.Boolean operator=WHEN_COMMA
if: IF type=kotlin.Boolean operator=WHEN_COMMA
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='5'
then: LITERAL Boolean type=kotlin.Boolean value='true'
else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='6'
if: WHEN type=kotlin.Boolean operator=WHEN_COMMA
if: WHEN type=kotlin.Boolean operator=WHEN_COMMA
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='5'
then: LITERAL Boolean type=kotlin.Boolean value='true'
else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='7'
then: LITERAL String type=kotlin.String value='567'
else: IF type=kotlin.String operator=WHEN
if: IF type=kotlin.Boolean operator=WHEN_COMMA
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='8'
then: LITERAL Boolean type=kotlin.Boolean value='true'
else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='9'
then: LITERAL String type=kotlin.String value='89'
else: LITERAL String type=kotlin.String value='?'
arg1: LITERAL Int type=kotlin.Int value='6'
then: LITERAL Boolean type=kotlin.Boolean value='true'
else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='7'
then: LITERAL String type=kotlin.String value='567'
if: WHEN type=kotlin.Boolean operator=WHEN_COMMA
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='8'
then: LITERAL Boolean type=kotlin.Boolean value='true'
else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null
arg1: LITERAL Int type=kotlin.Int value='9'
then: LITERAL String type=kotlin.String value='89'
else: LITERAL String type=kotlin.String value='?'