Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HasCallStack where error can occur #235

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Test/QuickCheck/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Test.QuickCheck.Random
import Data.List
import Data.Ord
import Data.Maybe
import GHC.Stack (HasCallStack)

--------------------------------------------------------------------------
-- ** Generator type
Expand Down Expand Up @@ -197,7 +198,7 @@ frequency xs0 = choose (1, tot) >>= (`pick` xs0)
pick _ _ = error "QuickCheck.pick used with empty list"

-- | Generates one of the given values. The input list must be non-empty.
elements :: [a] -> Gen a
elements :: HasCallStack => [a] -> Gen a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works with recent versions of GHC.

My call-stack package provides a shim for backwards compatibility. @nick8325 are you fine with adding that dependency? If yes, we could also add source locations to e.g. ===.

If not, we would want to CPP the HasCallStack => of the type signature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

elements [] = error "QuickCheck.elements used with empty list"
elements xs = (xs !!) `fmap` choose (0, length xs - 1)

Expand Down