Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Misleading compiler error for missing (sub-)arbitrary #51

Open
imRentable opened this issue Mar 11, 2020 · 3 comments
Open

Misleading compiler error for missing (sub-)arbitrary #51

imRentable opened this issue Mar 11, 2020 · 3 comments

Comments

@imRentable
Copy link

imRentable commented Mar 11, 2020

When I alter the README example to use an additional java.time.Instant field, like this:

import java.time.Instant

import com.danielasfregola.randomdatagenerator.magnolia.RandomDataGenerator

object MyApp extends App with RandomDataGenerator {

  case class Example(text: String, n: Int, inst: Instant)

  val example: Example = random[Example]
}

Then I get the following error messages:

  • Error: could not find implicit value for evidence parameter of type org.scalacheck.Arbitrary[Example]
  • Error: not enough arguments for method random: (implicit evidence$1: reflect.runtime.universe.WeakTypeTag[Example], implicit evidence$2: org.scalacheck.Arbitrary[Example])Example.

This is misleading because an Arbitrary[Example] can be created but not an Arbitrary[Instant]. If I add an implicit Arbitrary[Instant] in scope, it compiles just fine and yields the expected result.

Can this be improved?

@DanielaSfregola
Copy link
Owner

I am not sure it can, as this is a common issue of the typeclass derivation coming from the compiler - shapeless has similar behavior/issues.

Still, I'll have a thing - in the meanwhile suggestions are welcome.

Cheers,
D.

@stsatlantis
Copy link

@imRentable https://github.com/tek/splain can provide better error messages, maybe it helps in your case as well.

@imRentable
Copy link
Author

@stsatlantis Thanks for the info. I tried it but unfortunately it does not provide useful additional information in this case. However, cool plugin. :)

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

No branches or pull requests

3 participants