6

Can someone please explain to me why I get a 'diverging implicit expansion error' here? I think it has to do with the type synonym type MyIdType = String but I am not sure why.

import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary._
import org.scalacheck.Gen

def arbitraryCaseClass[A,C](f: A => C)(implicit t: Arbitrary[A]): Arbitrary[C] = Arbitrary(for(v <- arbitrary[A]) yield f(v))

type MyIdType = String

implicit val arbMyIdType: Arbitrary[MyIdType] = Arbitrary(Gen.identifier)

case class Foo(s: MyIdType, t: Int)

implicit def arbA = arbitraryCaseClass((Foo.apply _).tupled)

val foo = arbitrary[Foo].sample

error:

Error:(13, 40) diverging implicit expansion for type org.scalacheck.Arbitrary[(A$A6.this.MyIdType, Int)]
starting with method arbTuple2 in trait ArbitraryArities
implicit def arbA = arbitraryCaseClass((Foo.apply _).tupled)
dmz73
  • 1,588
  • 4
  • 20
  • 32
  • Maybe you should show the exact error and the line that causes it. – Jasper-M Mar 24 '16 at 15:16
  • You might've got hit by https://github.com/scala/bug/issues/8697 if the Arbitrary companion object defines `implicit object`s instead of implicit val/defs with explicit return types. – Dylan May 29 '19 at 18:30

0 Answers0