Comments (8)
It appears that RC6 is having trouble with the ImageSize
enumeration.
I'm still investigating the root cause, but in the meantime I think that providing an explicit Arbitrary
instance for ImageSize
should be a workaround.
from scalacheck-shapeless.
OK, I think I see what's happening here, although I don't entirely understand why the behaviour has changed between RC4 and RC6.
We can reproduce the problem with,
case class Foo(size: ImageSize)
implicitly[Arbitrary[Foo]]
The problem is with ScalaChecks definition of arbContainer2
... this pattern will match an HList
(with C[_, _]
as ::[_, _]
and the head and tail as T
and U
respectively). In context, T
is ImageSize
and U
is HNil
, ie. the generic representation of Foo
.
In attempting to resolve the implicit arguments of arbContainer2
the typechecker will start by attempting to resolve an arbitrary instance for (ImageSize, HNil)
. Either directly or indirectly this will loop back through the generic derivation and attempt to derive an instance for ImageSize :: HNil :: HNil
, which again matches arbContainer2
and we're off on a non-terminating regression.
I think it should be possible to fix this in scalacheck-shapeless somehow, probably by masking or deprioritizing arbContainer2
somehow. Most likely ScalaCheck could also be tweaked slightly to resolve the problem, but I don't think it would be reasonable to expect ScalaCheck to change to accommodate this scenario (/cc @rickynils)
The question for me is whether or not I can or should change shapeless to fix this. Ultimately that boils down to whether I can come up with a more sophisticated form of divergence checking which would catch this case without also excluding the kinds of recursion that we want to support. I don't currently have a clear idea of how to go about doing that.
I have, I suppose, been pretty much saying that using Lazy
means you're sure that the implicit resolution will converge, hence divergence checking should be suspended. The risk is that if you call that wrong then typechecking can loop, and that's what's happened here.
Thoughts on how best to proceed would be very welcome ...
from scalacheck-shapeless.
FWIW, I think the fix in ScalaCheck would be to move the implicit argument a: Arbitrary[(T, U)]
after the argument b: Buildable[(T,U),C[T,U]]
in the definition of arbContainer2
. b
won't resolve because there's no Buildable
for shapeless.::
(at least, I presume there isn't), so resolution of implicit arguments would stop there and not consider Arbitrary[(T, U)]
at all. /cc @rickynils.
from scalacheck-shapeless.
In fact, that might be a clue to a fix in scalacheck-shapeless ... the fix might be to duplicate arbContainer2
in object Shapeless
modified as described in my previous comment.
from scalacheck-shapeless.
@inthenow has verified locally that my suggested change in ScalaCheck does resolve the problem. So the change in scalacheck-shapeless should be good too.
from scalacheck-shapeless.
Thanks for having looked at this @milessabin and @inthenow ! (I was kind of busy with other projects of mine, I delayed looking at it). I'll try the workaround you suggest soon.
from scalacheck-shapeless.
@alexarchambault np. Btw, The new release of scalacheck has even better scalajs support, as shapeless itself now has. Had you considered cross-compiling this project to support scalajs? As an example, you could start with machinest
from scalacheck-shapeless.
Added Foo
and ImageSize
to the tests here: https://github.com/alexarchambault/scalacheck-shapeless/tree/topic/issue7
I'd like to have a more careful look at that, but with cached implicits, I got no divergence / infinite loop, just failed implicit derivation without https://github.com/alexarchambault/scalacheck-shapeless/blob/topic/issue7/src/test/scala/org/scalacheck/Definitions.scala#L65-L66
@inthenow I'll give scalajs a try if I can find some time to do it, looks like a good idea. (Thanks for the hint and the link.)
from scalacheck-shapeless.
Related Issues (20)
- Summon a generated instance without making it implicit
- SizeTests on 2.13 makes JVM segfault on JDK 13 and 14 HOT 6
- Add support for Scala Native
- Figuring out why an implicit could not be generated HOT 2
- implicit values in scope are not used, when diverging with `derivedArbitrary`
- Support for Scala 3 HOT 2
- Overwrite specific subtype of ADT?
- Unexpected diverging implicit with singleton type HOT 2
- Generator fails on nested case classes with sealed traits
- Avoiding generator failures when size is zero HOT 11
- Cogen[TestsDefinitions.T1.Tree] crashes HOT 5
- Shrinking of sealed trait hierarchy never terminates HOT 2
- Derivation of Arbitrary instances for scala.Enumerations HOT 1
- please publish for scala 2.12 HOT 1
- [Not an issue] Commendation HOT 2
- Unused Local Value Warning with Scala 2.12.4 when Using (Shapeless) Tagged Types
- Set the seed for Random
- Publish for ScalaCheck 1.14 HOT 2
- How to derive an Arbitrary explicitly HOT 2
- ClassCastException shrinking value class HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scalacheck-shapeless.