Hey everyone, I'm dabbling with extensions, and I'...
# arrow
z
Hey everyone, I'm dabbling with extensions, and I'm trying to get something to work based on an example in the docs:
Copy code
interface Eq<F> {
    fun F.eqv(b: F): Boolean
    fun F.neqv(b: F): Boolean = !eqv(b)
}

data class User(val id: Int) {
    companion object
}

@extension interface UserEq : Eq<User> {
    override fun User.eqv(b: User): Boolean = id == b.id
}
Now, I can make the
neqv
call work, as that extension is generated:
Copy code
val user1 = User(1)
val user2 = User(2)

user1.neqv(user2)
However, I don't get an
eqv
extension generated. I did get an
eq
extension that I could then open a scope on with
run
, but this isn't very neat:
Copy code
User.eq().run {
    user1.eqv(user2)
}
So... Is there something I could fix in my code to make Arrow generate the
eqv
extension that I could use like this?
Copy code
user1.eqv(user2) // right now, unresolved reference: eqv
k
I tried with 0.8.2 and I have the same issue as you. Seems like it does not generate the
eqv
as extension on the User type. Just he Companion obbject going to be generated
Copy code
fun User.neqv(b: User): Boolean = aaa.aaa.kioba.bbb.bbb.User.eq().run {
  this@neqv.neqv(b) as kotlin.Boolean
}

fun Companion.eq(): UserEq = object : aaa.aaa.kioba.bbb.bbb.UserEq {  }
with
0.8.2
I could end up generating the function with a workaround. Seems like the annotation will only generate the extension if the base interface has a default implementation. If you modify your EQ<F> interface according to this:
Copy code
interface Eq<F> {
  fun F.eqvImp(b: F): Boolean
  fun F.eqv(b: F): Boolean = eqvImp(b)
  fun F.neqv(b: F): Boolean = !eqvImp(b)
}
it will generate the
User.eqv
function for you. Edit: still trying to figure out the annotation processor why filtering out the functions with non default impl.
z
Maybe this is the intended behavior, but I'm hoping there's something I'm doing wrong to make this happen.
r
This seems like a bug, I checked the arrow instances in master and eqv is getting generated properly. For example for ListK:
Copy code
@JvmName("eqv")
@Suppress(
        "UNCHECKED_CAST",
        "USELESS_CAST",
        "EXTENSION_SHADOWED_BY_MEMBER",
        "UNUSED_PARAMETER"
)
fun <A> Kind<ForListK, A>.eqv(EQ: Eq<A>, arg1: Kind<ForListK, A>): Boolean = arrow.data.ListK.eq<A>(EQ).run {
  this@eqv.eqv(arg1) as kotlin.Boolean
}
I suggest you add an issue to arrow with a minimal repro example. It should always export that method.
👍 2