I have 2 methods ```fun <ACTUAL> expect( a...
# announcements
r
I have 2 methods
Copy code
fun <ACTUAL> expect(
  actual: ACTUAL,
  block: ObjectAssert<ACTUAL>.(ACTUAL) -> Unit
): ObjectAssert<ACTUAL>
and
Copy code
fun <ELEMENT> expect(
  actual: List<ELEMENT>,
  block: SoftAssertionListAssert<ELEMENT>.(List<ELEMENT>) -> Unit
): SoftAssertionListAssert<ELEMENT>
that the compiler is unable to distinguish between at the call site. I get why that’s an issue but confusingly I have overloads of both that only accept the first parameter:
Copy code
fun <ACTUAL> expect(actual: ACTUAL): AbstractObjectAssert<*, ACTUAL>
and
Copy code
fun <ELEMENT> expect(actual: List<ELEMENT>): ListAssert<ELEMENT>
that the compiler can distinguish. Can anyone enlighten me as to why one is a problem and no the other? Is there any way I can disambiguate the 2 param form?
k
Is there an inheritance relation between
SoftAssertionListAssert
and
ObjectAssert
?
a
@robfletcher can you give us an example how you try to invoke
expect
?
r
I was wondering about the inheritance relationship but no there is not.
Those are classes from AssertJ. I’m working on some Kotlin extensions for it.
The only solution I’ve found so far is to add a 2nd generic parameter to the list version but even then I have to specify the generic type at the call site
a
@robfletcher do you pass a lambda as the second parameter?
r
yes
I can get it to work by declaring the lambda as a variable with a specified type. That’s not ideal as I’m trying to create a reasonable test DSL. I’ll have to see if there’s another way I can disambiguate things
a
@robfletcher the problem is, that the kotlin-compiler needs to know the inputs/outputs of a lambda before it checks the body of the lambda. Thats why declaring the lambda before works. I don't really see a way around that apart from renaming one of the methods
r
yeah, it makes sense
thanks for the help