skiptools / skiptools/skip

Local lazy variables transpile to broken Kotlin

Open
#139 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

transpilation
Dominant language
Swift
Stars
3.2k
Forks
106
Avg merge
6d 13h
Merged PRs (30d)
1

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the Swift function example and tracing the transpiler logic that creates Kotlin equivalents for lazy variables. Done means the generated local Kotlin declaration compiles without an invalid private modifier and preserves the lazy variable behavior in function scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, swift
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.