Files
kotlin-fork/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.kt.txt
T
Denis.Zharkov a38040680c K2: Do not use KFunctionN as representation type for adapted references
Beside some corner cases, it's already prohibited in K1 because
adaptation have a bit strange nature
(they don't represent any existing real function exactly)

^KT-55137 Fixed
2023-02-15 08:13:45 +00:00

104 lines
2.1 KiB
Plaintext
Vendored

fun interface IFoo {
abstract fun foo(i: Int)
}
fun interface IFoo2 : IFoo {
}
object A {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
}
object B {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
}
operator fun A.get(i: IFoo): Int {
return 1
}
operator fun A.set(i: IFoo, newValue: Int) {
}
operator fun B.get(i: IFoo): Int {
return 1
}
operator fun B.set(i: IFoo2, newValue: Int) {
}
fun withVararg(vararg xs: Int): Int {
return 42
}
fun test1() {
{ // BLOCK
val <array>: A = A
val <index_0>: Function1<Int, Unit> = local fun withVararg(p0: Int) {
withVararg(xs = [p0])
}
<array>.set(i = <index_0> /*-> IFoo */, newValue = <array>.get(i = <index_0> /*-> IFoo */).plus(other = 1))
}
}
fun test2() {
{ // BLOCK
val <array>: B = B
val <index_0>: Function1<Int, Unit> = local fun withVararg(p0: Int) {
withVararg(xs = [p0])
}
<array>.set(i = <index_0> /*-> IFoo2 */, newValue = <array>.get(i = <index_0> /*-> IFoo */).plus(other = 1))
}
}
fun test3(fn: Function1<Int, Unit>) {
{ // BLOCK
val <array>: A = A
val <index_0>: Function1<Int, Unit> = fn
<array>.set(i = <index_0> /*-> IFoo */, newValue = <array>.get(i = <index_0> /*-> IFoo */).plus(other = 1))
}
}
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))
}
}
}
fun test5(a: Any) {
a as Function1<Int, Unit> /*~> Unit */
{ // BLOCK
val <array>: A = A
val <index_0>: Function1<Int, Unit> = a /*as Function1<Int, Unit> */
<array>.set(i = <index_0> /*-> IFoo */, newValue = <array>.get(i = <index_0> /*-> IFoo */).plus(other = 1))
}
}
fun test6(a: Any) {
a as Function1<Int, Unit> /*~> Unit */
a /*as Function1<Int, Unit> */ as IFoo /*~> Unit */
{ // BLOCK
val <array>: A = A
val <index_0>: Function1<Int, Unit> = a /*as Function1<Int, Unit> */
<array>.set(i = <index_0>, newValue = <array>.get(i = <index_0>).plus(other = 1))
}
}