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.
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.