angelolloqui / SwiftKotlin

A tool to convert Swift code to Kotlin.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swift 5.2 implicit return does not transpile properly

angelolloqui opened this issue · comments

The following swift code:

class A {
    var myVar: String {
        "test"
    }

    var state: Observable<RestaurantsListState> {
        get {
            myVar.asObservable()
        }
    }
    
    func myFunc() -> Int {
        2 + 5
    }
}

Returns this Kotlin:

class A {
    val myVar: String
        get() {
            "test"
        }

    val state: Observable<RestaurantsListState>
        get() {
            myVar.asObservable()
        }
    
    fun myFunc() : Int {
        2 + 5
    }
}

But that is not valid since it should either include return statements or preferably use the = like this:


class A {
    val myVar: String
        get() = "test"        

    val state: Observable<RestaurantsListState>
        get() = myVar.asObservable()        
    
    fun myFunc() : Int =
        2 + 5    
}

UPDATE: This is working for explicit returns, it is just happening with the new implicit ones from Swift5.2