typeable / generic-arbitrary

Generic method implementations for Arbitrary
MIT License
8 stars 7 forks source link

Ambiguous type compilation errors with sum types on GHC 9.4.1 and latest Hackage #17

Closed parsonsmatt closed 5 months ago

parsonsmatt commented 2 years ago

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

zyla commented 2 years 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:

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?

s9gf4ult commented 9 months ago

@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.

s9gf4ult commented 5 months ago

Looks like it is resolved

arybczak commented 1 month ago

Increasing the number of constraint solver iterations should not be considered a proper fix for this issue.