Skip to content

Kotlin SAM overload resolution ambiguity between Consumer and ThrowingConsumer #2357

@ansgarkonermann

Description

@ansgarkonermann

Summary

When using AssertJ Core 3.21.0 from Kotlin, an overload resolution ambiguity occurrs for methods having overloads which accept both Consumer and ThrowingConsumer.

Methods affected (list noncomprehensive)

org.assertj.core.api.AbstractAssert#satisfies(java.util.function.Consumer<? super ACTUAL>)
org.assertj.core.api.ObjectEnumerableAssert#allSatisfy(org.assertj.core.api.ThrowingConsumer<? super ELEMENT>)

Example

Worked before (typical syntax for Kotlin calling a method which takes a functional interface AKA "SAM")

assertThat(bounds).satisfies { // worked pre-3.21.0
    assertThat(it.startInclusive) // ... any detail assert statement
}

Wordy workaround:

assertThat(bounds).satisfies(Consumer {
    assertThat(it.startInclusive) // ... any detail assert statement
})

This overload ambiguity is (also) an issue of kotlin language design, cf. KT-17765

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    language: KotlinAn issue related to using AssertJ with Kotlin

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions