nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
706 stars 119 forks source link

Fix ambiguous use of `OVERLAPPING` instances in `genericShrink` #370

Closed MaximilianAlgehed closed 4 months ago

MaximilianAlgehed commented 4 months ago

As per the following documentation for how OVERLAPPING resolves (that I'm 99% sure is the same across all GHC versions) https://downloads.haskell.org/~ghc/7.10.1/docs/html/users_guide/type-class-extensions.html#instance-overlap the way that ghc resolves OVERLAPPING pragmas is that an instance that is OVERLAPPING will be chosen over one that isn't. It's not clear why the old code ever worked, possibly because GSubtermsIncl (K1 i a) a is a substitution of GSubtermsIncl (K1 i a) b...

Anway, with this change it's explicit that the GSubtermsIncl (K1 i a) a instance will be chosen over the GSubtermsIncl (K1 i a) b instance.

MaximilianAlgehed commented 4 months ago

While this does not alleviate the concern in #84 about GHC picking the "shrink to empty list" instance when it can't conclude that two types are equal, it does make the rules for choosing instances more clear. I'm not convinced that the issue raised in #84 is real, however.

Lysxia commented 4 months ago

It's not clear why the old code ever worked, possibly because GSubtermsIncl (K1 i a) a is a substitution of GSubtermsIncl (K1 i a) b...

Yes, that's why. The extra OVERLAPPING annotation was not ambiguous, but unnecessary.