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

Wrong in keyword in switch cases #113

Closed
angelolloqui opened this issue Mar 29, 2020 · 1 comment
Closed

Wrong in keyword in switch cases #113

angelolloqui opened this issue Mar 29, 2020 · 1 comment
Labels

Comments

@angelolloqui
Copy link
Owner

When using this code Swift code:

let nb = 42
switch nb {
    case 0: print("zero")
    case 1, 2, 3: print("low numbers")
    case 4...7, 8, 9: print("single digit")
    case 10: print("double digits")
    case 11...99: print("double digits")
    case 100...999: print("triple digits")
    default: print("four or more digits")
}

The resulting Kotlin is:

val nb = 42
when (nb) {
    0 -> print("zero")
    in 1, 2, 3 -> print("low numbers")
    in 4 .. 7, 8, 9 -> print("single digit")
    10 -> print("double digits")
    11 .. 99 -> print("double digits")
    100 .. 999 -> print("triple digits")
    else -> print("four or more digits")
}

However it should be:

val nb = 42
when (nb) {
    0 -> print("zero")
    1, 2, 3 -> print("low numbers")
    in 4 .. 7, 8, 9 -> print("single digit")
    10 -> print("double digits")
    in 11 .. 99 -> print("double digits")
    in 100 .. 999 -> print("triple digits")
    else -> print("four or more digits")
}

Note that the in prefix is correct in the case of expressions like 11...99

@angelolloqui
Copy link
Owner Author

Fixed with #115

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