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

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

Open
kaishh opened this issue Apr 25, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@kaishh
Copy link

commented Apr 25, 2019

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] {}
@szeiger

This comment has been minimized.

Copy link

commented Apr 26, 2019

I was going to change the title to say "compound type" but with actual intersection types in Dotty the problem still exists. In fact, it is worse in Dotty. Only Tc12[X] is found, Tc1[X] and Tc2[X] are also errors:

2 |  implicitly[Tc1[X]]
  |                    ^
  |no implicit argument of type Tc1[X] was found for parameter ev of method implicitly in object DottyPredef.
  |I found:
  |
  |    X.tc12[F](/* missing */implicitly[Proxy[Tc1]])
  |
  |But no implicit values were found that match type Proxy[Tc1].
3 |  implicitly[Tc2[X]]
  |                    ^
  |no implicit argument of type Tc2[X] was found for parameter ev of method implicitly in object DottyPredef.
  |I found:
  |
  |    X.tc12[F](/* missing */implicitly[Proxy[Tc2]])
  |
  |But no implicit values were found that match type Proxy[Tc2].
7 |  implicitly[Tc1[X] with Tc2[X]]
  |                                ^
  |no implicit argument of type Tc1[X] & Tc2[X] was found for parameter ev of method implicitly in object DottyPredef

Making Proxy covariant (trait Proxy[+F[x]]) fixes these additional problems that appear to be caused by changes in type inference. The original issue remains.

/cc @smarter

@smarter

This comment has been minimized.

Copy link

commented Apr 26, 2019

Please open an issue in the Dotty tracker

@kaishh

This comment has been minimized.

Copy link
Author

commented Apr 26, 2019

@smarter I opened dotty-related issues for this:
lampepfl/dotty#6384
lampepfl/dotty#6385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.