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

Missing is keyword in enum cases #114

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

Missing is keyword in enum cases #114

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

Comments

@angelolloqui
Copy link
Owner

angelolloqui commented Mar 29, 2020

This Swift code:

enum AnimationLengthAdvanced {
    case short
    case long
    case custom(Double)

    var duration: Double {
        switch self {
        case .short:
            return 2
        case .long:
            return 5.0
        case .custom(let duration):
            return duration
        }
    }
}

Translates to:

sealed class AnimationLengthAdvanced {
    object short : AnimationLengthAdvanced()
    object long : AnimationLengthAdvanced()
    data class custom(val v1: Double) : AnimationLengthAdvanced()

    val duration: Double
        get() {
            when (this) {
                short -> return 2
                long -> return 5.0
                custom -> return duration
            }
        }
}

But it should be:

sealed class AnimationLengthAdvanced {
    object short : AnimationLengthAdvanced()
    object long : AnimationLengthAdvanced()
    data class custom(val v1: Double) : AnimationLengthAdvanced()

    val duration: Double
        get() {
            when (this) {
                short -> return 2
                long -> return 5.0
                is custom -> return duration
            }
        }
}

Note that despite we do not have type information for the enums, we can deduct it is a class when the case comes with tuple information.

@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