Skip to content

Commit 99e6ed6

Browse files
committed
Catch missing 'Monad m' constraints too
1 parent d1b64bc commit 99e6ed6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ghcide/src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ suggestConstraint df parsedModule diag@Diagnostic {..}
739739
where
740740
findMissingConstraint :: T.Text -> Maybe T.Text
741741
findMissingConstraint t =
742-
let regex = "(No instance for|Could not deduce) \\((.+)\\) arising from a use of"
742+
let regex = "(No instance for|Could not deduce) \\((.+)\\) arising from" -- a use of / a do statement
743743
in matchRegexUnifySpaces t regex <&> last
744744

745745
-- | Suggests a constraint for an instance declaration for which a constraint is missing.

ghcide/test/exe/Main.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,13 @@ addFunctionConstraintTests = let
20432043
, "eq (Pair x y) (Pair x' y') = x == x' && y == y'"
20442044
]
20452045

2046+
missingMonadConstraint constraint = T.unlines
2047+
[ "module Testing where"
2048+
, "f :: " <> constraint <> "m ()"
2049+
, "f = do "
2050+
, " return ()"
2051+
]
2052+
20462053
check :: String -> T.Text -> T.Text -> T.Text -> TestTree
20472054
check testName actionTitle originalCode expectedCode = testSession testName $ do
20482055
doc <- createDoc "Testing.hs" "haskell" originalCode
@@ -2089,6 +2096,11 @@ addFunctionConstraintTests = let
20892096
"Add `Eq b` to the context of the type signature for `eq`"
20902097
(incompleteConstraintSourceCodeWithNewlinesInTypeSignature "Eq a")
20912098
(incompleteConstraintSourceCodeWithNewlinesInTypeSignature "Eq a, Eq b")
2099+
, check
2100+
"missing Monad constraint"
2101+
"Add `Monad m` to the context of the type signature for `f`"
2102+
(missingMonadConstraint "")
2103+
(missingMonadConstraint "Monad m => ")
20922104
]
20932105

20942106
removeRedundantConstraintsTests :: TestTree

0 commit comments

Comments
 (0)