David Kubecka
06/26/2024, 8:19 AMimport 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):
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.)CLOVIS
06/26/2024, 8:24 AMDavid Kubecka
06/26/2024, 8:31 AMpublic 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.CLOVIS
06/26/2024, 8:32 AM