Skip to content

Type alias causes problems for implicit search #7993

Closed
@travisbrown

Description

@travisbrown

minimized code

trait TC[F[_]]

object TC {
  def check[F[_], A](x: F[A])(implicit F: TC[F]): Unit = ()
}

case class Foo[+E, +A](value: A)

object Foo {
  type WithList[+E, +A] = Foo[List[E], A]

  implicit def instance[E]: TC[[x] =>> Foo[E, x]] =
    new TC[[x] =>> Foo[E, x]] {}
}

val x1: Foo[List[String], Int] = Foo(1)
val x2: Foo.WithList[String, Int] = Foo(1)

TC.check(x1)
TC.check(x2)
Compilation output
20 |TC.check(x2)
   |            ^
   |no implicit argument of type TC[([+A] => Foo.WithList[String, A])] was found for parameter F of method check in object TC.
   |I found:
   |
   |    Foo.instance[Nothing]
   |
   |But method instance in object Foo does not match type TC[([+A] => Foo.WithList[String, A])].

expectation

This is a minimization from the Cats tests, and the Scala 2 equivalent (using either kind-projector or ({ type L[x] = ... })#L for the type lambda) has no problems with this code.

Note that removing the variance annotation on the A in WithList resolves the issue for Dotty, but this isn't an option for Cats.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions