Navigation Menu

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

"diverging implicits" when searching for a covariant typeclass #8877

Open
scabug opened this issue Oct 2, 2014 · 1 comment
Open

"diverging implicits" when searching for a covariant typeclass #8877

scabug opened this issue Oct 2, 2014 · 1 comment

Comments

@scabug
Copy link

scabug commented Oct 2, 2014

Discovered this bug in the discussion of scodec/scodec#26

here is a minimal test case that fails:

    trait Decoder[+A]
    trait Codec[A] extends Decoder[A]
    trait F[+A]
    
    object Foo {
      implicit def foo[A:Codec]: Codec[F[A]] = null
      val x = implicitly[Decoder[F[Int]]]
    }

trying to compile this gives me:

    [info] /Users/v724000/devel/variancebad/src/main/scala/foo.scala:7: foo is not a valid implicit value for Codec[A] because:
    [info] hasMatchingSymbol reported error: diverging implicit expansion for type Codec[A]
    [info] starting with method foo in object Foo
    [info]       val x = implicitly[Decoder[F[Int]]]

If I add the variance annotation to Codec, or if I remove the variance annotation from either F or Decoder then it does the right thing (which is to give me implicit not found instead of diverging implicits).

If I add an implicit Codec for Int:

          implicit val int: Codec[Int] = null

it compiles in 2.10.4 but in 2.11.2 I still get diverging implicits.

@scabug
Copy link
Author

scabug commented Oct 2, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8877?orig=1
Reporter: Stew O'Connor (stew)
Affected Versions: 2.10.4, 2.11.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant