From 62f071c0e7ebfff4c9b15872e67c8d9a8ded671b Mon Sep 17 00:00:00 2001 From: Morrow Date: Thu, 27 Jan 2022 15:58:46 +0200 Subject: [PATCH] Fix #1879 --- .../src/Wingman/KnownStrategies/QuickCheck.hs | 5 +++-- plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs | 1 + .../golden/GoldenArbitrarySingleConstructor.expected.hs | 7 +++++++ .../test/golden/GoldenArbitrarySingleConstructor.hs | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 plugins/hls-tactics-plugin/test/golden/GoldenArbitrarySingleConstructor.expected.hs create mode 100644 plugins/hls-tactics-plugin/test/golden/GoldenArbitrarySingleConstructor.hs diff --git a/plugins/hls-tactics-plugin/src/Wingman/KnownStrategies/QuickCheck.hs b/plugins/hls-tactics-plugin/src/Wingman/KnownStrategies/QuickCheck.hs index 4cc1d4afb8..b14e4b8348 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/KnownStrategies/QuickCheck.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/KnownStrategies/QuickCheck.hs @@ -43,8 +43,9 @@ deriveArbitrary = do mempty mempty mempty - $ noLoc $ - let' [valBind (fromString "terminal") $ list $ fmap genExpr terminal] $ + $ noLoc $ case terminal of + [onlyCon] -> genExpr onlyCon -- See #1879 + _ -> let' [valBind (fromString "terminal") $ list $ fmap genExpr terminal] $ appDollar (mkFunc "sized") $ lambda [bvar' (mkVarOcc "n")] $ case' (infixCall "<=" (mkVal "n") (int 1)) [ match [conP (fromString "True") []] $ diff --git a/plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs index 9322b0912b..4075183ee6 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs @@ -72,6 +72,7 @@ spec = do describe "known" $ do autoTest 25 13 "GoldenArbitrary" + autoTest 6 13 "GoldenArbitrarySingleConstructor" autoTestNoWhitespace 6 10 "KnownBigSemigroup" autoTest 4 10 "KnownThetaSemigroup" diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenArbitrarySingleConstructor.expected.hs b/plugins/hls-tactics-plugin/test/golden/GoldenArbitrarySingleConstructor.expected.hs new file mode 100644 index 0000000000..786e381ca8 --- /dev/null +++ b/plugins/hls-tactics-plugin/test/golden/GoldenArbitrarySingleConstructor.expected.hs @@ -0,0 +1,7 @@ +data Gen a + +data Obj = Obj Int Bool Char String + +arbitrary :: Gen Obj +arbitrary + = (((Obj <$> arbitrary) <*> arbitrary) <*> arbitrary) <*> arbitrary \ No newline at end of file diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenArbitrarySingleConstructor.hs b/plugins/hls-tactics-plugin/test/golden/GoldenArbitrarySingleConstructor.hs new file mode 100644 index 0000000000..a6a7d171a3 --- /dev/null +++ b/plugins/hls-tactics-plugin/test/golden/GoldenArbitrarySingleConstructor.hs @@ -0,0 +1,6 @@ +data Gen a + +data Obj = Obj Int Bool Char String + +arbitrary :: Gen Obj +arbitrary = _ \ No newline at end of file