Skip to content

Commit de0c69d

Browse files
committed
Fix remove constraint for signatures with forall
1 parent 8e7855f commit de0c69d

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

ghcide/test/exe/Main.hs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2574,6 +2574,7 @@ addImplicitParamsConstraintTests =
25742574
"fCaller :: " <> mkContext contextCaller <> "()",
25752575
"fCaller = fBase"
25762576
]
2577+
25772578
removeRedundantConstraintsTests :: TestTree
25782579
removeRedundantConstraintsTests = let
25792580
header =
@@ -2582,6 +2583,13 @@ removeRedundantConstraintsTests = let
25822583
, ""
25832584
]
25842585

2586+
headerExt :: [T.Text] -> [T.Text]
2587+
headerExt exts =
2588+
redunt : extTxt ++ ["module Testing where"]
2589+
where
2590+
redunt = "{-# OPTIONS_GHC -Wredundant-constraints #-}"
2591+
extTxt = map (\ext -> "{-# LANGUAGE " <> ext <> " #-}") exts
2592+
25852593
redundantConstraintsCode :: Maybe T.Text -> T.Text
25862594
redundantConstraintsCode mConstraint =
25872595
let constraint = maybe "" (\c -> "" <> c <> " => ") mConstraint
@@ -2604,6 +2612,25 @@ removeRedundantConstraintsTests = let
26042612
, "foo x = x == 1"
26052613
]
26062614

2615+
redundantConstraintsForall :: Maybe T.Text -> T.Text
2616+
redundantConstraintsForall mConstraint =
2617+
let constraint = maybe "" (\c -> "" <> c <> " => ") mConstraint
2618+
in T.unlines $ headerExt ["RankNTypes"] <>
2619+
[ "foo :: forall a. " <> constraint <> "a -> a"
2620+
, "foo = id"
2621+
]
2622+
2623+
typeSignatureNested :: Maybe T.Text -> T.Text
2624+
typeSignatureNested mConstraint =
2625+
let constraint = maybe "" (\c -> "" <> c <> " => ") mConstraint
2626+
in T.unlines $ header <>
2627+
[ "f :: Int -> ()"
2628+
, "f = g"
2629+
, " where"
2630+
, " g :: " <> constraint <> "a -> ()"
2631+
, " g _ = ()"
2632+
]
2633+
26072634
typeSignatureMultipleLines :: T.Text
26082635
typeSignatureMultipleLines = T.unlines $ header <>
26092636
[ "foo :: (Num a, Eq a, Monoid a)"
@@ -2615,7 +2642,7 @@ removeRedundantConstraintsTests = let
26152642
check actionTitle originalCode expectedCode = testSession (T.unpack actionTitle) $ do
26162643
doc <- createDoc "Testing.hs" "haskell" originalCode
26172644
_ <- waitForDiagnostics
2618-
actionsOrCommands <- getCodeActions doc (Range (Position 4 0) (Position 4 maxBound))
2645+
actionsOrCommands <- getAllCodeActions doc
26192646
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
26202647
executeCodeAction chosenAction
26212648
modifiedCode <- documentContents doc
@@ -2641,6 +2668,14 @@ removeRedundantConstraintsTests = let
26412668
"Remove redundant constraints `(Monoid a, Show a)` from the context of the type signature for `foo`"
26422669
(redundantMixedConstraintsCode $ Just "Monoid a, Show a")
26432670
(redundantMixedConstraintsCode Nothing)
2671+
, check
2672+
"Remove redundant constraint `Eq a` from the context of the type signature for `g`"
2673+
(typeSignatureNested $ Just "Eq a")
2674+
(typeSignatureNested Nothing)
2675+
, check
2676+
"Remove redundant constraint `Eq a` from the context of the type signature for `foo`"
2677+
(redundantConstraintsForall $ Just "Eq a")
2678+
(redundantConstraintsForall Nothing)
26442679
, checkPeculiarFormatting
26452680
"should do nothing when constraints contain an arbitrary number of spaces"
26462681
typeSignatureSpaces

0 commit comments

Comments
 (0)