Skip to content

Intersection type implicit can't be found when obscured by a type parameter #11502

@neko-kai

Description

@neko-kai

Example:

trait Tc1[A]
trait Tc2[A]
trait Tc12[A] extends Tc1[A] with Tc2[A]

trait Proxy[F[x]]
object Proxy {
  implicit val proxy: Proxy[Tc12] = new Proxy[Tc12] {}
}

final case class X()
object X {
  implicit def tc12[F[x] >: Tc12[x]: Proxy]: F[X] = new Tc12[X] {}
}

object app extends App {
  implicitly[Tc1[X]]
  implicitly[Tc2[X]]
  implicitly[Tc12[X]]
  // all good

  implicitly[Tc1[X] with Tc2[X]]
  // Error:(19, 13) could not find implicit value for parameter e: Tc1[X] with Tc2[X]
  //  implicitly[Tc1[X] with Tc2[X]]
}

Note, changing the return type of X's instance to F[X] with F[X] or applying an identity type lambda magically works around the issue, even though both transformations are tautological:

implicit def tc12[F[x] >: Tc12[x]: Proxy]: F[X] with F[X] = new Tc12[X] {}
type Fixup[A] = A
implicit def tc12[F[x] >: Tc12[x]: Proxy]: Fixup[F[X]] = new Tc12[X] {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)implicit

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions