Type inference from takeIf statements

#1

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){
    any
        ?.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
#2

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

2 Likes