Type inference from takeIf statements

My thought is that takeIf statements should be able to influence type inference.
Hopefully the scenario below demonstrates what I mean:

fun someFunction(any: Any?, bool: Boolean){
        ?.takeIf{ it is Boolean }
        ?.let { it && bool } // error: "Type Mismatch\n Required: Boolean\n Found: Any"

Any thoughts?

EDIT: Changed ‘any’ to ‘it’

1 Like

Change .takeIf{ any is Boolean } with let { any as? Boolean }