Skip to content

isUsedAsResultOfLambda

Whether the value of the given KtExpression is used as the resulting expression of some lambda block.

Note that isUsedAsResultOfLambda performs a conservative check instead of exhaustive control-flow analysis and isUsedAsResultOfLambda being true doesn't imply that the containing lambda itself is used.

It's also vital to not confuse lambda expressions with regular scope blocks (like if branches).

Example

In the following examples, x is used as a result of a lambda (x.isUsedAsResultOfLambda == true):

  • { x -> println(0); x }

  • { { x }; 5 }

In these expressions, x is not used as a result of a lambda (x.isUsedAsResultOfLambda == false)

  • { x -> println(0); x + 1 }

  • { x; println(50) }

  • { if (true) { x } else { x } }

  • fun(x: Int) = x