Hello. I encountered a case where "usedAsExpressio...
# k2-adopters
r
Hello. I encountered a case where "usedAsExpression" property for "when" expression returns false, while I'm expecting it should return true.
Copy code
fun test(c: Boolean, d: Boolean) {
    val a = if (c) {
        val b = "One"
        if (d) {
            b
        } else {
            "Two"
        }
    } else {
        "Three"
    }
}
Here, "usedAsExpression" for the outer "if" is true, while for the inner "if" is false. Is that correct? Obviously, the inner "if" is used as expression as well as the outer one. How can I check that condition beside "usedAsExpression" property?
d
FirWhenExpression.usedAsExpression
is initialized only based on source structure without any resolution and it might be not precise
So you can expect false-negatives from it (but not false-positives)
r
So, the only option here is to do analysis of this expression on my side? K1 API worked in this case...
d
Yes, it is the only option
Note that
usedAsExpression
is an internal implementation detail without any contracts for outer consumers