Kroppeb
12/22/2022, 10:22 AMinline fun destructInlineLambda(x: () -> Int) {
val (a, b, c) = x
println("$a$b$c")
}
inline operator fun (() -> Int).component1() = this().toString()[0] - '0'
inline operator fun (() -> Int).component2() = this().toString()[0] - '0'
inline operator fun (() -> Int).component3() = this().toString()[0] - '0'
Now, running this with destructInlineLambda{456}
prints "456" to the console as expected. However I get 4 warnings, all 3 operator functions had the typical "nothing to inline" warning ("Expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types"), and at the place where x
is used I got this: "Deprecated usage of inline-parameter 'x' in 'public final inline fun destructInlineLambda(x: () -> Int): Unit defined in pkg.TestDestructors'. Add 'noinline' modifier to the parameter declaration. See https://youtrack.jetbrains.com/issue/KT-52502"
Now this is weird cause they are all wrong. The component functions get properly inlined as can be shown below, and the KT-52502 assumes (quote:) "However, extension receivers are implicitly noinline", which again see below is not true.
run{
for (i in 990..1010)
destructInlineLambda{if (i in 100..999) i else return@run}
}
println("bye")
This compiles and runs as expected, meaning that the lambda had to be inlined for the return@run
to work.
Should I make multiple bug reports for this / do there already exists reports for these?Kroppeb
12/22/2022, 10:25 AMelizarov
12/22/2022, 10:37 AMinline
are perfectly reasonable. There is no reason to mark those extensions as inline
. However, the no-inline status of receivers should be better documented, indeed. To be fair, using functional types in the receiver position is extremely rare in Kotlin.Kroppeb
12/22/2022, 10:51 AMKroppeb
12/22/2022, 10:57 AMx
is only present in IntelliJ idea and in the online playground, but running the compiler on the code only produces warnings for the "useless" inline
and not for x
elizarov
12/22/2022, 11:00 AMKroppeb
12/22/2022, 11:43 AMx
to be passed as a receiver to the componentN
functions. I checked this by included non local returns in the lambda and running and by checking decompiled bytecode for multiple cases.Kroppeb
12/22/2022, 11:55 AMKroppeb
12/22/2022, 2:01 PMelizarov
12/22/2022, 2:08 PM