I suppose this is very niche..: Can I initialize c...
# getting-started
h
I suppose this is very niche..: Can I initialize class member `val`s from a lambda while also forbidding non-local returns in that lambda? • If I want to allow non-local returns, I can do this: playground example. Using the non-local return in this case actually triggers an error for kotlin 2 (not for 1.9.25), but for a different reason. It's easy to give an example where the non-local return is allowed also in kotlin 2. • marking the lambda
crossinline
, forbids the non-local return, but I can no longer initialize member `val`s from the lambda. I can initialize member `var`s, and local `val`s. See playground example here. I don't understand why initializing member
val
would no longer be possible. ◦ When trying to initialize a member
val
kotlin 1.9.25 errors "Captured values initialization is forbidden due to possible reassignment" (is the contract not understood here?) and kotlin 2 errors "Initialization of captured member values must be inlined" (is it not inlined?)