@@ -2594,6 +2594,7 @@ addImplicitParamsConstraintTests =
2594
2594
" fCaller :: " <> mkContext contextCaller <> " ()" ,
2595
2595
" fCaller = fBase"
2596
2596
]
2597
+
2597
2598
removeRedundantConstraintsTests :: TestTree
2598
2599
removeRedundantConstraintsTests = let
2599
2600
header =
@@ -2602,6 +2603,13 @@ removeRedundantConstraintsTests = let
2602
2603
, " "
2603
2604
]
2604
2605
2606
+ headerExt :: [T. Text ] -> [T. Text ]
2607
+ headerExt exts =
2608
+ redunt : extTxt ++ [" module Testing where" ]
2609
+ where
2610
+ redunt = " {-# OPTIONS_GHC -Wredundant-constraints #-}"
2611
+ extTxt = map (\ ext -> " {-# LANGUAGE " <> ext <> " #-}" ) exts
2612
+
2605
2613
redundantConstraintsCode :: Maybe T. Text -> T. Text
2606
2614
redundantConstraintsCode mConstraint =
2607
2615
let constraint = maybe " " (\ c -> " " <> c <> " => " ) mConstraint
@@ -2624,6 +2632,25 @@ removeRedundantConstraintsTests = let
2624
2632
, " foo x = x == 1"
2625
2633
]
2626
2634
2635
+ redundantConstraintsForall :: Maybe T. Text -> T. Text
2636
+ redundantConstraintsForall mConstraint =
2637
+ let constraint = maybe " " (\ c -> " " <> c <> " => " ) mConstraint
2638
+ in T. unlines $ (headerExt [" RankNTypes" ]) <>
2639
+ [ " foo :: forall a. " <> constraint <> " a -> a"
2640
+ , " foo = id"
2641
+ ]
2642
+
2643
+ typeSignatureNested :: Maybe T. Text -> T. Text
2644
+ typeSignatureNested mConstraint =
2645
+ let constraint = maybe " " (\ c -> " " <> c <> " => " ) mConstraint
2646
+ in T. unlines $ header <>
2647
+ [ " f :: Int -> ()"
2648
+ , " f = g"
2649
+ , " where"
2650
+ , " g :: " <> constraint <> " a -> ()"
2651
+ , " g _ = ()"
2652
+ ]
2653
+
2627
2654
typeSignatureMultipleLines :: T. Text
2628
2655
typeSignatureMultipleLines = T. unlines $ header <>
2629
2656
[ " foo :: (Num a, Eq a, Monoid a)"
@@ -2635,7 +2662,7 @@ removeRedundantConstraintsTests = let
2635
2662
check actionTitle originalCode expectedCode = testSession (T. unpack actionTitle) $ do
2636
2663
doc <- createDoc " Testing.hs" " haskell" originalCode
2637
2664
_ <- waitForDiagnostics
2638
- actionsOrCommands <- getCodeActions doc ( Range ( Position 4 0 ) ( Position 4 maxBound ))
2665
+ actionsOrCommands <- getAllCodeActions doc
2639
2666
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
2640
2667
executeCodeAction chosenAction
2641
2668
modifiedCode <- documentContents doc
@@ -2661,6 +2688,14 @@ removeRedundantConstraintsTests = let
2661
2688
" Remove redundant constraints `(Monoid a, Show a)` from the context of the type signature for `foo`"
2662
2689
(redundantMixedConstraintsCode $ Just " Monoid a, Show a" )
2663
2690
(redundantMixedConstraintsCode Nothing )
2691
+ , check
2692
+ " Remove redundant constraint `Eq a` from the context of the type signature for `g`"
2693
+ (typeSignatureNested $ Just " Eq a" )
2694
+ (typeSignatureNested Nothing )
2695
+ , check
2696
+ " Remove redundant constraint `Eq a` from the context of the type signature for `foo`"
2697
+ (redundantConstraintsForall $ Just " Eq a" )
2698
+ (redundantConstraintsForall Nothing )
2664
2699
, checkPeculiarFormatting
2665
2700
" should do nothing when constraints contain an arbitrary number of spaces"
2666
2701
typeSignatureSpaces
0 commit comments