FIR DFA: unwrap transparent expressions in more places

This commit is contained in:
pyos
2022-11-11 19:44:14 +01:00
committed by teamcity
parent 2e9cccd809
commit ae31275f73
11 changed files with 117 additions and 104 deletions
@@ -0,0 +1,47 @@
FILE fqName:<root> fileName:/whenWithSubjectVariable.kt
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.Any declared in <root>'
CONST Int type=kotlin.Int value=1
FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test (): kotlin.Int declared in <root>'
BLOCK type=kotlin.Int origin=WHEN
VAR name:y type:kotlin.Any [val]
CALL 'public final fun foo (): kotlin.Any declared in <root>' type=kotlin.Any origin=null
WHEN type=kotlin.Int origin=WHEN
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val y: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
arg1: CONST Int type=kotlin.Int value=42
then: CONST Int type=kotlin.Int value=1
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.String
GET_VAR 'val y: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
then: CALL 'public open fun <get-length> (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY
$this: TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String
GET_VAR 'val y: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=kotlin.Int
GET_VAR 'val y: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
then: CONST Int type=kotlin.Int value=2
BRANCH
if: CALL 'public open fun contains (value: kotlin.Int): kotlin.Boolean [operator] declared in kotlin.ranges.IntRange' type=kotlin.Boolean origin=IN
$this: CALL 'public final fun rangeTo (other: kotlin.Int): kotlin.ranges.IntRange [operator] declared in kotlin.Int' type=kotlin.ranges.IntRange origin=RANGE
$this: CONST Int type=kotlin.Int value=0
other: CONST Int type=kotlin.Int value=10
value: TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int
GET_VAR 'val y: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
then: CONST Int type=kotlin.Int value=3
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=null
$this: CALL 'public open fun contains (value: kotlin.Int): kotlin.Boolean [operator] declared in kotlin.ranges.IntRange' type=kotlin.Boolean origin=IN
$this: CALL 'public final fun rangeTo (other: kotlin.Int): kotlin.ranges.IntRange [operator] declared in kotlin.Int' type=kotlin.ranges.IntRange origin=RANGE
$this: CONST Int type=kotlin.Int value=10
other: CONST Int type=kotlin.Int value=20
value: TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int
GET_VAR 'val y: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
then: CONST Int type=kotlin.Int value=4
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Int type=kotlin.Int value=-1
@@ -0,0 +1,17 @@
fun foo(): Any {
return 1
}
fun test(): Int {
return { // BLOCK
val y: Any = foo()
when {
EQEQ(arg0 = y, arg1 = 42) -> 1
y is String -> y /*as String */.<get-length>()
y !is Int -> 2
0.rangeTo(other = 10).contains(value = y /*as Int */) -> 3
10.rangeTo(other = 20).contains(value = y /*as Int */).not() -> 4
else -> -1
}
}
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_K2: JVM_IR
// !LANGUAGE: +VariableDeclarationInWhenSubject
fun foo(): Any = 1
@@ -11,4 +10,4 @@ fun test() =
in 0..10 -> 3
!in 10..20 -> 4
else -> -1
}
}