alexarchambault / scalacheck-shapeless

Generation of arbitrary case classes / ADTs instances with scalacheck and shapeless
Apache License 2.0
239 stars 35 forks source link

Figuring out why an implicit could not be generated #206

Closed dmateusp closed 3 years ago

dmateusp commented 3 years ago

I'm trying to generate an Arbitrary for a pretty long class which has many types, the class is itself generated through a macro (using a library called SCIO Beam).

For a simple generated class I'm able to use scalacheck-shapeless to generate an Arbitrary instance, but for a bigger class I'm not able to. How can I debug why generating the implicit failed? I imagine one cause could be a specific type for which no Arbitrary was found?

To illustrate, this is working:

@BigQueryType.fromStorage(
    "<redacted>"
)
class Test
// Generates a class with two columns, one of type String and one of type Long

it should "work" in {
    implicitly[Arbitrary[Test]]
    // It was able to create the implicit!
    val genTest: Gen[Test] = Arbitrary.arbitrary[Test]

    ...
}

But for another class generated from a BigQuery table with many columns, it's not finding the implicit.

Do I have a way to explicitly invoke what generates the implicit method that we fetch with implicitly[Arbitrary[Test]] ? And grab the potential Failure?

joroKr21 commented 3 years ago

I would give https://github.com/tek/splain a try (btw it will be soon merged into Scala proper)

dmateusp commented 3 years ago

@joroKr21 thanks for the suggestion, I tried adding:

addCompilerPlugin("io.tryp" % "splain" % "0.5.8" cross CrossVersion.patch),

which pointed me to a missing implicit for Joda Date, which I fixed using

implicit val genJodaLocalDate: Arbitrary[LocalDate] = Arbitrary(genDateTime.map(_.toLocalDate()))

Thanks a lot!