what am I doing wrong? I also cant compile the cod...
# getting-started
j
what am I doing wrong? I also cant compile the code. The function itself has no error
Copy code
inline fun <V, reified T> enum(name: String, description: String, required: Boolean = false) where T : EnumWithValue<V>, T : Enum<T> {
        val values = enumValues<T>()
        when(values[0].value) {
            is Int -> int(name, description, required) {
                values.forEach { enum -> choice(enum.name, enum.value as Int) }
            }
            is Double -> number(name, description, required) {
                values.forEach { enum -> choice(enum.name, enum.value as Double) }
            }
            is String -> string(name, description, required) {
                values.forEach { enum -> choice(enum.name, enum.value as String) }
            }
            else -> throw IllegalArgumentException("Enum values must be of type Int, Double or String")
        }
    }
k
Maybe because
enum
is a reserved keyword. Is it the same if you rename the function name and all inner
enum
params to something else?
j
Same problem, also the function used later to get these values back has the same problem
m
A while back I had a problem with official builders (I have no idea what an OptionBuilder is) and reported an official tracker on the youtrack. Can you explicitly type the builder if thats a thing?
j
I think its a problem with the generics all other functions in this builder scope work fine
But I have no idea whats wrong with the generics
Okay the problem was that the method required 2 type parameters. But weird error. Tho shouldn't Kotlin like know what the type is because the first parameter (T) has the value type?
Copy code
where T : EnumWithValue<V>, T : Enum<T>
Because always doing enum<Int, ComponentType> seems a bit redunant?
or is this possibly a bug?
h
This is not a compile error, it's an error in the compiler – I'd say it's probably a bug.