@@ -3036,6 +3036,26 @@ addFunctionConstraintTests = let
3036
3036
, " eq (Pair x y) (Pair x' y') = x == x' && y == y'"
3037
3037
]
3038
3038
3039
+ -- See https://github.com/haskell/haskell-language-server/issues/4648
3040
+ -- When haddock comment appears after the =>, code action was introducing the
3041
+ -- new constraint in the comment
3042
+ incompleteConstraintSourceCodeWithCommentInTypeSignature :: T. Text -> T. Text
3043
+ incompleteConstraintSourceCodeWithCommentInTypeSignature constraint =
3044
+ T. unlines
3045
+ [ " module Testing where"
3046
+ , " data Pair a b = Pair a b"
3047
+ , " eq "
3048
+ , " :: (" <> constraint <> " )"
3049
+ , " =>"
3050
+ , " -- This is the first argument"
3051
+ , " Pair a b ->"
3052
+ , " -- And this is the second"
3053
+ , " Pair a b ->"
3054
+ , " -- And this is the result"
3055
+ , " Bool"
3056
+ , " eq (Pair x y) (Pair x' y') = x == x' && y == y'"
3057
+ ]
3058
+
3039
3059
missingMonadConstraint constraint = T. unlines
3040
3060
[ " module Testing where"
3041
3061
, " f :: " <> constraint <> " m ()"
@@ -3079,6 +3099,11 @@ addFunctionConstraintTests = let
3079
3099
" Add `Eq b` to the context of the type signature for `eq`"
3080
3100
(incompleteConstraintSourceCodeWithNewlinesInTypeSignature " Eq a" )
3081
3101
(incompleteConstraintSourceCodeWithNewlinesInTypeSignature " Eq a, Eq b" )
3102
+ , checkCodeAction
3103
+ " preexisting constraint, with haddock comment in type signature"
3104
+ " Add `Eq b` to the context of the type signature for `eq`"
3105
+ (incompleteConstraintSourceCodeWithCommentInTypeSignature " Eq a" )
3106
+ (incompleteConstraintSourceCodeWithCommentInTypeSignature " Eq a, Eq b" )
3082
3107
, checkCodeAction
3083
3108
" missing Monad constraint"
3084
3109
" Add `Monad m` to the context of the type signature for `f`"
0 commit comments