K2: add more tests/fix augmented assignment case around KT-59748

This commit is contained in:
Mikhail Glukhikh
2023-07-25 16:13:49 +02:00
committed by Space Team
parent f20e2dec31
commit 5836a8aa0b
16 changed files with 182 additions and 37 deletions
@@ -10,3 +10,20 @@ fun bar(list: MutableList<Any?>, condition: Boolean): Unit = <!RETURN_TYPE_MISMA
condition -> list.set(0, "")
else -> Unit
}<!>
fun plusFoo(list: MutableList<String>, condition: Boolean): Unit = when {
condition -> list[0] += ""
else -> Unit
}
var x: String = ""
fun assign(condition: Boolean): Unit = when {
condition -> x = ""
else -> Unit
}
fun plugAssign(condition: Boolean): Unit = when {
condition -> x += ""
else -> Unit
}
@@ -25,3 +25,48 @@ FILE: listAssignmentInWhen.fir.kt
}
}
public final fun plusFoo(list: R|kotlin/collections/MutableList<kotlin/String>|, condition: R|kotlin/Boolean|): R|kotlin/Unit| {
^plusFoo when () {
R|<local>/condition| -> {
{
{
lval <array>: R|kotlin/collections/MutableList<kotlin/String>| = R|<local>/list|
lval <index_0>: R|kotlin/Int| = Int(0)
R|<local>/<array>|.R|SubstitutionOverride<kotlin/collections/MutableList.set: R|kotlin/String|>|(R|<local>/<index_0>|, R|<local>/<array>|.R|SubstitutionOverride<kotlin/collections/MutableList.get: R|kotlin/String|>|(R|<local>/<index_0>|).R|kotlin/String.plus|(String()))
}
Unit
}
}
else -> {
Q|kotlin/Unit|
}
}
}
public final var x: R|kotlin/String| = String()
public get(): R|kotlin/String|
public set(value: R|kotlin/String|): R|kotlin/Unit|
public final fun assign(condition: R|kotlin/Boolean|): R|kotlin/Unit| {
^assign when () {
R|<local>/condition| -> {
R|/x| = String()
}
else -> {
Q|kotlin/Unit|
}
}
}
public final fun plugAssign(condition: R|kotlin/Boolean|): R|kotlin/Unit| {
^plugAssign when () {
R|<local>/condition| -> {
R|/x| = R|/x|.R|kotlin/String.plus|(String())
}
else -> {
Q|kotlin/Unit|
}
}
}
@@ -10,3 +10,20 @@ fun bar(list: MutableList<Any?>, condition: Boolean): Unit = <!TYPE_MISMATCH!>wh
condition -> list.set(0, "")
else -> Unit
}<!>
fun plusFoo(list: MutableList<String>, condition: Boolean): Unit = when {
condition -> list[0] += ""
else -> Unit
}
var x: String = ""
fun assign(condition: Boolean): Unit = when {
condition -> x = ""
else -> Unit
}
fun plugAssign(condition: Boolean): Unit = when {
condition -> x += ""
else -> Unit
}
@@ -174,19 +174,20 @@ FILE fqName:<root> fileName:/caoWithAdaptationForSam.kt
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.IFoo
GET_VAR 'fn: kotlin.Function1<kotlin.Int, kotlin.Unit> declared in <root>.test4' type=kotlin.Function1<kotlin.Int, kotlin.Unit> origin=null
then: BLOCK type=kotlin.Unit origin=null
VAR IR_TEMPORARY_VARIABLE name:tmp_6 type:<root>.A [val]
GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.A
VAR IR_TEMPORARY_VARIABLE name:tmp_7 type:<root>.IFoo [val]
TYPE_OP type=<root>.IFoo origin=IMPLICIT_CAST typeOperand=<root>.IFoo
GET_VAR 'fn: kotlin.Function1<kotlin.Int, kotlin.Unit> declared in <root>.test4' type=kotlin.Function1<kotlin.Int, kotlin.Unit> origin=null
CALL 'public final fun set (i: <root>.IFoo, newValue: kotlin.Int): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
$receiver: GET_VAR 'val tmp_6: <root>.A declared in <root>.test4' type=<root>.A origin=null
i: GET_VAR 'val tmp_7: <root>.IFoo declared in <root>.test4' type=<root>.IFoo origin=null
newValue: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null
$this: CALL 'public final fun get (i: <root>.IFoo): kotlin.Int declared in <root>' type=kotlin.Int origin=null
$receiver: GET_VAR 'val tmp_6: <root>.A declared in <root>.test4' type=<root>.A origin=null
i: GET_VAR 'val tmp_7: <root>.IFoo declared in <root>.test4' type=<root>.IFoo origin=null
other: CONST Int type=kotlin.Int value=1
BLOCK type=kotlin.Unit origin=null
VAR IR_TEMPORARY_VARIABLE name:tmp_6 type:<root>.A [val]
GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.A
VAR IR_TEMPORARY_VARIABLE name:tmp_7 type:<root>.IFoo [val]
TYPE_OP type=<root>.IFoo origin=IMPLICIT_CAST typeOperand=<root>.IFoo
GET_VAR 'fn: kotlin.Function1<kotlin.Int, kotlin.Unit> declared in <root>.test4' type=kotlin.Function1<kotlin.Int, kotlin.Unit> origin=null
CALL 'public final fun set (i: <root>.IFoo, newValue: kotlin.Int): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
$receiver: GET_VAR 'val tmp_6: <root>.A declared in <root>.test4' type=<root>.A origin=null
i: GET_VAR 'val tmp_7: <root>.IFoo declared in <root>.test4' type=<root>.IFoo origin=null
newValue: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null
$this: CALL 'public final fun get (i: <root>.IFoo): kotlin.Int declared in <root>' type=kotlin.Int origin=null
$receiver: GET_VAR 'val tmp_6: <root>.A declared in <root>.test4' type=<root>.A origin=null
i: GET_VAR 'val tmp_7: <root>.IFoo declared in <root>.test4' type=<root>.IFoo origin=null
other: CONST Int type=kotlin.Int value=1
FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
@@ -76,9 +76,11 @@ fun test3(fn: Function1<Int, Unit>) {
fun test4(fn: Function1<Int, Unit>) {
when {
fn is IFoo -> { // BLOCK
val <array>: A = A
val <index_0>: IFoo = fn /*as IFoo */
<array>.set(i = <index_0>, newValue = <array>.get(i = <index_0>).plus(other = 1))
{ // BLOCK
val <array>: A = A
val <index_0>: IFoo = fn /*as IFoo */
<array>.set(i = <index_0>, newValue = <array>.get(i = <index_0>).plus(other = 1))
}
}
}
}