Skip to content

Different treatment of the Aux pattern between Dotty/scalac #3590

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

Closed
OlivierBlanvillain opened this issue Nov 29, 2017 · 0 comments
Closed

Comments

@OlivierBlanvillain
Copy link
Contributor

Here is a minimized example showing a small difference between Dotty and scalac handling of the "Aux pattern". The issue is that when asking for an implicit Tagged.Aux[T, _] instead of Tagged[T], Dotty won't consider the companion object of T as part of the its implicit scopes.

trait Tagged[T]

object Tagged {
  type Aux[T, UNUSED] = Tagged[T]
}

trait Fun[R] {
  type Out
}

object Fun extends Fun0 {
  // In Dotty there is a difference between asking for Tagged.Aux[T, Int]
  // and asking for Tagged[T]. In the former case the companion of T is
  // not considered as a valid scope during implicit search. In scalac
  // both cases are treated equally.
  implicit def tagged[T](implicit t: Tagged.Aux[T, Int]): Fun[T] { type Out = Int } = ???
}

trait Fun0 {
  implicit def default[T]: Fun[T] { type Out = String } = ???
}

object FunDemo extends App {
  case class A(x: Int, y: String)
  object A {
    implicit val tag: Tagged[A] = ???
  }

  // Precise version of implicitly that keeps type members
  def the[T <: AnyRef](implicit ev: T): ev.type = ev

  val adhl = the[Fun[A]]

  // Compiles in scalac: the tagged case wins the implicit search using A.tag
  // Does not compile in Dotty: because of Tagged.Aux[T, _] the companion
  //                            object of T is not explored during the search,
  //                            it fallbacks to default (type Out = String)
  identity[Fun[A] { type Out = Int }](adhl)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant