Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit conversion into a dependent type is not found #11791

Open
neko-kai opened this issue Nov 1, 2019 · 0 comments

Comments

@neko-kai
Copy link

@neko-kai neko-kai commented Nov 1, 2019

Example:

trait X1[A] {
  def x1: A => A
}
object X1 {
  implicit def X2[A]: X2[A] = new X2[A] {
    override def x2: A => A = identity
    override def x1: A => A = identity
  }
}

trait X2[A] extends X1[A] {
  def x2: A => A
}

object X {
  implicit def toX12[A](self: X.type)(implicit x: X1[A]): x.type = x
}

object example extends App {
  def x1[A: X1](a: A) = {
    X.x1(a)
  }
  def x2[A: X2](a: A) = {
    X.x2(a)
  }
  println(x1(2))
}

Expected:

X.x2(a) call to compile, but got an error message:

Error:(26, 7) value x2 is not a member of object X
    X.x2(a)

Note that the example works in dotty 0.20 as expected: https://scastie.scala-lang.org/Tusgmci0Toau5WI58FSZTQ

Workaround:

Explicitly listing creating prioritized conversions for all subtypes of X1:

object X extends LowPriorityX {
  implicit def toX1[A](self: X.type)(implicit x: X1[A]): X1[A] = x
}
trait LowPriorityX {
  implicit def toX2[A](self: X.type)(implicit x: X2[A]): X2[A] = x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.