https://kotlinlang.org logo
Title
j

Jan

02/03/2022, 3:21 PM
what am I doing wrong? I also cant compile the code. The function itself has no error
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

Kirill Grouchnikov

02/03/2022, 3:27 PM
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

Jan

02/03/2022, 3:32 PM
Same problem, also the function used later to get these values back has the same problem
m

Michael de Kaste

02/03/2022, 4:08 PM
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

Jan

02/03/2022, 4:25 PM
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?
where T : EnumWithValue<V>, T : Enum<T>
Because always doing enum<Int, ComponentType> seems a bit redunant?
or is this possibly a bug?
h

hho

02/04/2022, 8:33 AM
This is not a compile error, it's an error in the compiler – I'd say it's probably a bug.