Contract to indicate boolean state in lambda function?

I have built the following implementation of unless:

inline fun unless(cond: Boolean, fn: () -> Unit) {
    contract { callsInPlace(fn, InvocationKind.AT_MOST_ONCE) }
    if (!cond) {

Is there a way to specify in the contract that fn will only be invoked if cond is false? That is needed in order for smart casts to work in the following code:

unless(x is Foo) {
    throw SomeException("x is not Foo");
x.someMethodOnFoo() // This will not smart cast

Is there a way to achieve this?

It cannot smart cast because the lambda could not throw an exception in which case the x would not be of type Foo.

For example:

unless(x is Foo) {
    println("x is not Foo");

How ever if you are always going to throw an exception, you could change the signature and the contract to something like:

inline fun unless(cond: Boolean, fn: () -> Nothing) {
    contract { returns() implies cond }
    if (!cond) fn()

In that case the smart cast will succeed.

Yes. That is clear to me. However, since the function is inlined, I would have expected the Kotlin compiler to be able to figure this out. Arguably it should be able to find that out even without any contracts.