Closed parsonsmatt closed 5 months ago
I can reproduce the error with the following program, on both GHC 9.2.4 and 9.4.2:
{-# LANGUAGE DeriveGeneric #-}
{-# OPTIONS_GHC -fconstraint-solver-iterations=4 #-}
module EnumTest where
import GHC.Generics
import Test.QuickCheck
import Test.QuickCheck.Arbitrary.Generic
data Country = PL | GB | RU | RO | CZ | HR | SK | DE | NL | ES | BR
deriving (Generic)
instance Arbitrary Country where
arbitrary = genericArbitrary
shrink = genericShrink
Behavior is different depending on -fconstraint-solver-iterations
:
with -fconstraint-solver-iterations=4
, I get both solveWanteds: too many iterations (limit = 4)
and Ambiguous type variables ‘af0’, ‘bf0’ arising from a use of ‘genericArbitrary’
with -fconstraint-solver-iterations=5
, I see only solveWanteds: too many iterations (limit = 5)
, no ambiguous type error
with -fconstraint-solver-iterations=6
, it compiles fine.
I don't know much about the GHC constraint solver, but maybe the ambiguous type error can arise due to an intermediate state the solver is left in after iteration limit is exhausted?
@parsonsmatt It looks like the issue is related to the -fconstraint-solver-iterations
parameter. The @zyla 's example is added to tests.
In conclusion: for GHC from 8.10
to 9.0
it is enough to set it to 5, but for newer versions 6 is required.
I do not really understand the real reason of the issue, but there is simple workaround: just set -fconstraint-solver-iterations=6
or higher.
Please confirm the issue is resolved.
Looks like it is resolved
Increasing the number of constraint solver iterations should not be considered a proper fix for this issue.
With a plain sum type, on GHC 9.4.1, we get ambiguous type variable errors when trying to write
instance Arbitrary X where arbitrary = genericArbitrary
Apologies for the bad issue, I'll work up a reproduction soon