kotest / kotest-extensions-arrow

Kotest extensions for Arrow
Apache License 2.0
40 stars 13 forks source link

shouldBeLeft() messes up typing #99

Closed shalomhalbert closed 2 years ago

shalomhalbert commented 2 years ago

shouldBeLeft()'s contract appears to mess up typing. In the example below, it in actual.mapLeft { it } should be a Throwable, but because actual.shouldBeLeft() is called first, it is of type Any?. This appears to be caused by shouldBeLeft()'s contract

contract {
        returns() implies (this@shouldBeLeft is Either.Left<*>)
    }

Example:

import arrow.core.Either
import arrow.core.left
import io.kotest.assertions.arrow.either.shouldBeLeft
import io.kotest.core.spec.style.StringSpec
import java.lang.IllegalArgumentException

class Right

class Sample: StringSpec({
    "Example"{
            val actual: Either<Throwable, Right> = IllegalArgumentException().left()

            actual.shouldBeLeft()
            actual.mapLeft { it } //Why is [it] of type Any?
        }
})
i-walker commented 2 years ago

This is an issue in your example.

val actual: Either<Throwable, Int> = IllegalArgumentException().left()

    actual.shouldBeLeft()
    actual.mapLeft { it } // it is properly resolved to Throwable

Do you have another example or repo I can check out?

shalomhalbert commented 2 years ago

Apologies, this was caused by me referencing 1.0.1 instead of 1.1.1, which has a different contract.

i-walker commented 2 years ago

No apologies needed 😄 @shalbert94