K2: generate Unit conversion for indexed assignment at raw FIR stage
#KT-59748 Fixed
This commit is contained in:
committed by
Space Team
parent
1832413a02
commit
f20e2dec31
@@ -0,0 +1,14 @@
|
||||
// ISSUE: KT-59748
|
||||
// WITH_STDLIB
|
||||
|
||||
fun foo(list: MutableList<Any?>, condition: Boolean): Unit = when {
|
||||
condition -> list[0] = "OK"
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val list = mutableListOf<Any?>("FAIL")
|
||||
foo(list, true)
|
||||
foo(list, false)
|
||||
return list[0] as String
|
||||
}
|
||||
@@ -5,7 +5,7 @@ package kt235
|
||||
fun main() {
|
||||
val array = MyArray()
|
||||
val f: () -> String = <!INITIALIZER_TYPE_MISMATCH!>{
|
||||
<!TYPE_MISMATCH!>array[2] = 23<!> //error: Type mismatch: inferred type is Int (!!!) but String was expected
|
||||
array[2] = 23 //error: Type mismatch: inferred type is Int (!!!) but String was expected
|
||||
}<!>
|
||||
val g: () -> String = <!INITIALIZER_TYPE_MISMATCH!>{
|
||||
var x = 1
|
||||
@@ -17,11 +17,11 @@ fun main() {
|
||||
}<!>
|
||||
val array1 = MyArray1()
|
||||
val i: () -> String = <!INITIALIZER_TYPE_MISMATCH!>{
|
||||
<!TYPE_MISMATCH!>array1[2] = 23<!>
|
||||
array1[2] = 23
|
||||
}<!>
|
||||
|
||||
val fi: () -> String = <!INITIALIZER_TYPE_MISMATCH!>{
|
||||
<!TYPE_MISMATCH!>array[2] = 23<!>
|
||||
array[2] = 23
|
||||
}<!>
|
||||
val gi: () -> String = <!INITIALIZER_TYPE_MISMATCH!>{
|
||||
var x = 1
|
||||
|
||||
+1
@@ -7,6 +7,7 @@ FILE: setOperatorOnDynamic.fir.kt
|
||||
)
|
||||
lval x3: R|kotlin/Any| = R|kotlin/arrayOf|<R|kotlin/String|>().R|kotlin/collections/fold|<R|kotlin/String|, R|dynamic|>(R|kotlin/js/js|(String(({}))), <L> = fold@fun <anonymous>(res: R|dynamic|, key: R|kotlin/String|): R|dynamic| <inline=Inline, kind=UNKNOWN> {
|
||||
R|<local>/res|.R|<dynamic>/set|(vararg(R|<local>/key|, String(hello)))
|
||||
Unit
|
||||
^ R|<local>/res|
|
||||
}
|
||||
)
|
||||
|
||||
Vendored
+2
@@ -29,6 +29,7 @@ FILE: unsafeAssignmentExtra.fir.kt
|
||||
public final fun main(arg: R|kotlin/Any|, condition: R|kotlin/Boolean|): R|kotlin/Unit| {
|
||||
lval value: R|Foo<kotlin/Int>| = R|/myBuilder|<R|kotlin/Int|>(<L> = myBuilder@fun R|Foo<kotlin/Int>|.<anonymous>(): R|kotlin/Unit| <inline=NoInline> {
|
||||
this@R|special/anonymous|.R|SubstitutionOverride</Foo.b: R|kotlin/Array<Stub (chain inference): TypeVariable(T)>|>|.R|SubstitutionOverride<kotlin/Array.set: R|kotlin/Unit|>|(Int(0), Int(123))
|
||||
Unit
|
||||
this@R|special/anonymous|.R|SubstitutionOverride</Foo.a: R|Stub (chain inference): TypeVariable(T)|>| = Int(45)
|
||||
{
|
||||
lval <unary>: R|kotlin/Int| = this@R|special/anonymous|.R|SubstitutionOverride</Foo.a: R|Stub (chain inference): TypeVariable(T)|>|
|
||||
@@ -103,6 +104,7 @@ FILE: unsafeAssignmentExtra.fir.kt
|
||||
this@R|special/anonymous|.R|SubstitutionOverride</Foo.accept: R|kotlin/Unit|>|(String())
|
||||
this@R|special/anonymous|.R|SubstitutionOverride</Foo.a: R|Stub (chain inference): TypeVariable(T)|>| = Int(45)
|
||||
this@R|special/anonymous|.R|SubstitutionOverride</Foo.b: R|kotlin/Array<Stub (chain inference): TypeVariable(T)>|>|.R|SubstitutionOverride<kotlin/Array.set: R|kotlin/Unit|>|(Int(0), Int(123))
|
||||
Unit
|
||||
R|<local>/baz|(this@R|special/anonymous|.R|SubstitutionOverride</Foo.a: R|Stub (chain inference): TypeVariable(T)|>|)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// ISSUE: KT-59748
|
||||
// FIR_DUMP
|
||||
|
||||
fun foo(list: MutableList<Any?>, condition: Boolean): Unit = <!RETURN_TYPE_MISMATCH!>when {
|
||||
fun foo(list: MutableList<Any?>, condition: Boolean): Unit = when {
|
||||
condition -> list[0] = ""
|
||||
else -> Unit
|
||||
}<!>
|
||||
}
|
||||
|
||||
fun bar(list: MutableList<Any?>, condition: Boolean): Unit = <!RETURN_TYPE_MISMATCH!>when {
|
||||
condition -> list.set(0, "")
|
||||
|
||||
@@ -2,7 +2,11 @@ FILE: listAssignmentInWhen.fir.kt
|
||||
public final fun foo(list: R|kotlin/collections/MutableList<kotlin/Any?>|, condition: R|kotlin/Boolean|): R|kotlin/Unit| {
|
||||
^foo when () {
|
||||
R|<local>/condition| -> {
|
||||
R|<local>/list|.R|SubstitutionOverride<kotlin/collections/MutableList.set: R|kotlin/Any?|>|(Int(0), String())
|
||||
{
|
||||
R|<local>/list|.R|SubstitutionOverride<kotlin/collections/MutableList.set: R|kotlin/Any?|>|(Int(0), String())
|
||||
Unit
|
||||
}
|
||||
|
||||
}
|
||||
else -> {
|
||||
Q|kotlin/Unit|
|
||||
|
||||
Reference in New Issue
Block a user