While testing the newest beta (`2.0.0-Beta5`) I no...
# eap
m
While testing the newest beta (
2.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 🧵
youtrack 1
✅ 1
Copy code
class 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.
Copy code
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.
k
@udalov any ideas?
u
Looks like an unwanted side effect of KT-45375, in which case
-Xlambdas=class
can help as a workaround. Please report an issue and I'll investigate.
m
Sorry for the delay, here is the ticket: https://youtrack.jetbrains.com/issue/KT-67368