I'm running into a strange problem regarding test assertions on computed enums: ```import org.assert...
d
I'm running into a strange problem regarding test assertions on computed enums:
Copy code
import org.assertj.core.api.Assertions.assertThat

enum class X(val input: String) { A("1"), B("2") }

fun test() {
    assertThat(X::input.of("1"))
}

// generic enum reverse lookup
inline fun <reified E : Enum<E>, V> ((E) -> V).of(value: V): E =
    enumValues<E>().firstOrNull { this(it) == value } ?: error("No enum constant ${E::class}.$value")
The
assertThat
expression fails to compile with
Overload resolution ambiguity. All these functions match.
To fix the issue it suffices to extract the computed enum value into a variable (but still having the type inferred):
Copy code
val actual = X::input.of("1")
        assertThat(actual)
What's going on? (I have briefly tried to simplify the reproducer, e.g. by using a simpler enum-returning function, but to no avail.)
c
> Overload resolution ambiguity. All these functions match. The error message should give you the list of functions that do match. One of them should be your function, the other ones will tell you why the compiler is confused.
d
Sure, there is quite a huge list of those functions. That's why I didn't even try to paste it here 🙂 But there are obvious nonsenses such as
Copy code
public open fun assertThat(actual: File!): AbstractFileAssert<*>! defined in org.assertj.core.api.Assertions
Surely the return value of
of
is not
File
... But mainly wonder why the simple extraction to a val "fixes" the problem. That seems strange and that's why I think there must be something more going on.
c
Looks like a resolution bug, you should report it: https://kotl.in/issue
👍 1