skip icon indicating copy to clipboard operation
skip copied to clipboard

Local lazy variables transpile to broken Kotlin

Open hepspl opened this issue 1 year ago • 1 comments

I noticed the problem after creating a lazy var inside a function.

Swift: func example() { lazy var lazyVariable = { return Int.random(in: 1...10) } print(lazyVariable) }

Transpiler created Kotlin code: internal open fun example() { var lazyVariable = l@{ -> return@l Int.random(in_ = 1..10) } private var lazyVariableinitialized = false print(lazyVariable) }

Which results in error:

Modifier 'private' is not applicable to 'local variable'

image

Do you think you could improve your logic for creating lazy variables equivalents in Kotlin so they could also work in function scope, not only the class scope?

hepspl avatar Jun 07 '24 09:06 hepspl

Thanks for the report! I'll think about how we might implement this. At the very least we need to issue an unsupported error rather than generating bad code.

aabewhite avatar Jun 11 '24 22:06 aabewhite