`quickCheckAll` ignores property with implicit parameters
In the following example, the prop_foo property is ignored when quickCheckAll is used:
$ cat Test1.hs
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck
prop_foo :: (?y :: Int) => Int -> Bool
prop_foo x = x + ?y == ?y + x
prop_bar :: Int -> Int -> Bool
prop_bar x y = x + y == y + x
-- Template Haskell hack to make the following $quickCheckAll work
-- under GHC 7.8.
return []
-- | All tests as collected by 'quickCheckAll'.
tests :: IO Bool
tests = do
putStrLn "Tests"
$quickCheckAll
where ?y = 4
And GHCi reports:
GHCi> :load Test1.hs
[1 of 1] Compiling Main ( Test1.hs, interpreted )
Test1.hs:20:3: warning:
Name prop_foo found in source file but was not in scope
|
20 | $quickCheckAll
| ^^^^^^^^^^^^^^
GHCi> tests
Tests
=== prop_bar from Test1.hs:9 ===
+++ OK, passed 100 tests.
True
The above example was tested with GHC 8.2.2 and QuickCheck 2.10.1.
The fix of this issue would facilitate the fix of https://github.com/agda/agda/issues/2861.
CC'ing @andreasabel.
The following line of code is what does the in-scope checking:
exists <- (warning x >> return False) `recover` (reify (mkName x) >> return True)
I tried replacing reify (mkName x) with lookupValueName x, which doesn't emit a warning, but I then get this error from GHC:
Test.hs:21:3: error:
• Can't represent implicit parameters in Template Haskell: ?y::Int
• In the untyped splice: $quickCheckAll
|
21 | $quickCheckAll
| ^^^^^^^^^^^^^^
It looks as though GHC doesn't support reifying a function which takes implicit parameters. I can't think of any workaround for this in QuickCheck - the only thing I can suggest is using Data.Reflection instead of implicit parameters.
I just tested this on HEAD and it now works. Closing this as completed.
I just tested this on
HEADand it now works. Closing this as completed.
I confirm the issue was fixed (tested with GHC 9.8.2 and QuickCheck 2.14.3). Thanks!