molikuner
04/05/2024, 2:01 PM2.0.0-Beta5
) I noticed that there is a slight behavioural change with regards to where null checks are being generated in (local) lambdas. See the example code in the 🧵molikuner
04/05/2024, 2:01 PMclass Foo(
private val bar: Bar,
) {
fun foo() {
val foobar = bar.getIt()
val x = { foobar }
x.invoke()
}
open class Bar {
open fun getIt(): String {
return "something"
}
}
}
Before, i.e. <2.0.0-Beta5, this code didn’t generate null checks in the lambda. Starting from Beta5 it does, thus the following test starts failing whereas previously it didn’t.
import org.junit.jupiter.api.Test
import org.mockito.kotlin.mock
internal class FooTest {
private val bar: Foo.Bar = mock()
private val foo = Foo(bar)
@Test
fun `crashes with 2_0_0-Beta5 works with 2_0_0-Beta4`() {
foo.foo()
}
}
I’m not sure whether it’s expected or I should open a bug report for it, as you should probably not rely on this behaviour that it was technically possible to return null
from a function on the JVM that defined a non-null return type. Please let me in case I should open a bug ticket.kirillrakhman
04/09/2024, 1:28 PMudalov
-Xlambdas=class
can help as a workaround. Please report an issue and I'll investigate.molikuner
04/12/2024, 3:06 PM