Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch cases with where clauses not translated properly #57

Open
angelolloqui opened this issue Dec 5, 2017 · 0 comments
Open

Switch cases with where clauses not translated properly #57

angelolloqui opened this issue Dec 5, 2017 · 0 comments
Labels

Comments

@angelolloqui
Copy link
Owner

In Swift, switch cases can contain where clauses like the following:

switch exception {
case .generic(let error) where error != nil:
    trackError(name: "generic", message: error!)
default:
    trackError(name: "generic", message: R.string.localizable.generic_error())
}

Currently, SwiftKotlin generates:

when (exception) {
    .generic where error != null -> trackError(name = "generic", message = error!!)
    else -> trackError(name = "generic", message = R.string.localizable.generic_error())
}

But that is incorrect Kotlin. It should instead remove the variable from the when and use expressions for the cases. Like:

when {
    exception is Exception.generic && error != null -> trackError(name = "generic", message = error!!)
    else -> trackError(name = "generic", message = R.string.localizable.generic_error())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant