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

Redundant . character when converting enum #112

Closed
igorwojda opened this issue Mar 27, 2020 · 2 comments
Closed

Redundant . character when converting enum #112

igorwojda opened this issue Mar 27, 2020 · 2 comments
Labels

Comments

@igorwojda
Copy link

Swift source

enum User: String {
    case jane = "Jane"
    case joe = "Joe"
    
    var uuid: String {
        switch self {
        case .jane:
            return "abc"
        case .joe:
            return "cde"
        }
    }
}

Kotlin Result

enum class User (val rawValue: String) {
    jane("Jane"), joe("Joe");

    companion object {
        operator fun invoke(rawValue: String) = User.values().firstOrNull { it.rawValue == rawValue }
    }
    
    val uuid: String
        get() {
            when (this) {
                .jane -> return "abc"
                .joe -> return "cde"
            }
        }
}

Kotlin Expected result (no dot in the when element)

enum class User (val rawValue: String) {
    jane("Jane"), joe("Joe");

    companion object {
        operator fun invoke(rawValue: String) = User.values().firstOrNull { it.rawValue == rawValue }
    }
    
    val uuid: String
        get() {
            when (this) {
                jane -> return "abc"
                joe -> return "cde"
            }
        }
}

BTW if we want to follow kotlin naming conventions we should make these enum const names uppercase
https://kotlinlang.org/docs/reference/coding-conventions.html#property-names

@angelolloqui
Copy link
Owner

angelolloqui commented Mar 29, 2020

This one will be fixed in next release (WIP).

Regarding the naming conventions, I intentionally decided not to modify them. The main reason is that since we do not have type information, we could be breaking code afterwards when transpiling the code that uses it. Besides, code convention transformation could be built as a post process by implementing a TokenTransformPlugin that modifies it accordingly.

If you want to contribute, feel free to create such a plugin (plugins can be enabled or disabled easily by final users)

@angelolloqui
Copy link
Owner

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

2 participants