skiptools / skip

Skip transpiler for creating SwiftUI apps for iOS and Android
https://skip.tools
GNU Lesser General Public License v3.0
1.43k stars 38 forks source link

Transpilation problem with lazy variables inside a function #139

Open hepspl opened 3 months ago

hepspl commented 3 months ago

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?

aabewhite commented 2 months ago

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.