Skip to content

Commit ab1d5cb

Browse files
wavewave9999years
authored andcommitted
fix addTypeAnnotationsToLiteralsTest
1 parent 3f75e54 commit ab1d5cb

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,18 @@ suggestAddTypeAnnotationToSatisfyConstraints sourceOpt Diagnostic{_range=_range,
828828
| otherwise = []
829829
where
830830
makeAnnotatedLit ty lit = "(" <> lit <> " :: " <> ty <> ")"
831+
#if MIN_VERSION_ghc(9,4,0)
832+
pat multiple at inArg inExpr = T.concat [ ".*Defaulting the type variable "
833+
, ".*to type ‘([^ ]+)’ "
834+
, "in the following constraint"
835+
, if multiple then "s" else ""
836+
, ".*arising from the literal ‘(.+)’"
837+
, if inArg then ".+In the.+argument" else ""
838+
, if at then ".+at" else ""
839+
, if inExpr then ".+In the expression" else ""
840+
, ".+In the expression"
841+
]
842+
#else
831843
pat multiple at inArg inExpr = T.concat [ ".*Defaulting the following constraint"
832844
, if multiple then "s" else ""
833845
, " to type ‘([^ ]+)’ "
@@ -837,12 +849,12 @@ suggestAddTypeAnnotationToSatisfyConstraints sourceOpt Diagnostic{_range=_range,
837849
, if inExpr then ".+In the expression" else ""
838850
, ".+In the expression"
839851
]
852+
#endif
840853
codeEdit ty lit replacement =
841854
let title = "Add type annotation ‘" <> ty <> "’ to ‘" <> lit <> ""
842855
edits = [TextEdit _range replacement]
843856
in [( title, edits )]
844857

845-
846858
-- | GHC strips out backticks in case of infix functions as well as single quote
847859
-- in case of quoted name when using TemplateHaskellQuotes. Which is not desired.
848860
--

plugins/hls-refactor-plugin/test/Main.hs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,11 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
25302530
, ""
25312531
, "f = 1"
25322532
])
2533+
#if MIN_VERSION_ghc(9,4,0)
2534+
[ (DsWarning, (3, 4), "Defaulting the type variable") ]
2535+
#else
25332536
[ (DsWarning, (3, 4), "Defaulting the following constraint") ]
2537+
#endif
25342538
"Add type annotation ‘Integer’ to ‘1’"
25352539
(T.unlines [ "{-# OPTIONS_GHC -Wtype-defaults #-}"
25362540
, "module A (f) where"
@@ -2547,7 +2551,11 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
25472551
, " let x = 3"
25482552
, " in x"
25492553
])
2554+
#if MIN_VERSION_ghc(9,4,0)
2555+
[ (DsWarning, (4, 12), "Defaulting the type variable") ]
2556+
#else
25502557
[ (DsWarning, (4, 12), "Defaulting the following constraint") ]
2558+
#endif
25512559
"Add type annotation ‘Integer’ to ‘3’"
25522560
(T.unlines [ "{-# OPTIONS_GHC -Wtype-defaults #-}"
25532561
, "module A where"
@@ -2565,7 +2573,11 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
25652573
, " let x = let y = 5 in y"
25662574
, " in x"
25672575
])
2576+
#if MIN_VERSION_ghc(9,4,0)
2577+
[ (DsWarning, (4, 20), "Defaulting the type variable") ]
2578+
#else
25682579
[ (DsWarning, (4, 20), "Defaulting the following constraint") ]
2580+
#endif
25692581
"Add type annotation ‘Integer’ to ‘5’"
25702582
(T.unlines [ "{-# OPTIONS_GHC -Wtype-defaults #-}"
25712583
, "module A where"
@@ -2584,9 +2596,15 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
25842596
, ""
25852597
, "f = seq \"debug\" traceShow \"debug\""
25862598
])
2599+
#if MIN_VERSION_ghc(9,4,0)
2600+
[ (DsWarning, (6, 8), "Defaulting the type variable")
2601+
, (DsWarning, (6, 16), "Defaulting the type variable")
2602+
]
2603+
#else
25872604
[ (DsWarning, (6, 8), "Defaulting the following constraint")
25882605
, (DsWarning, (6, 16), "Defaulting the following constraint")
25892606
]
2607+
#endif
25902608
("Add type annotation ‘" <> listOfChar <> "’ to ‘\"debug\"")
25912609
(T.unlines [ "{-# OPTIONS_GHC -Wtype-defaults #-}"
25922610
, "{-# LANGUAGE OverloadedStrings #-}"
@@ -2596,7 +2614,7 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
25962614
, ""
25972615
, "f = seq (\"debug\" :: " <> listOfChar <> ") traceShow \"debug\""
25982616
])
2599-
, knownBrokenForGhcVersions [GHC92] "GHC 9.2 only has 'traceShow' in error span" $
2617+
, knownBrokenForGhcVersions [GHC92, GHC94] "GHC 9.2 only has 'traceShow' in error span" $
26002618
testSession "add default type to satisfy two constraints" $
26012619
testFor
26022620
(T.unlines [ "{-# OPTIONS_GHC -Wtype-defaults #-}"
@@ -2607,7 +2625,11 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
26072625
, ""
26082626
, "f a = traceShow \"debug\" a"
26092627
])
2628+
#if MIN_VERSION_ghc(9,4,0)
2629+
[ (DsWarning, (6, 6), "Defaulting the type variable") ]
2630+
#else
26102631
[ (DsWarning, (6, 6), "Defaulting the following constraint") ]
2632+
#endif
26112633
("Add type annotation ‘" <> listOfChar <> "’ to ‘\"debug\"")
26122634
(T.unlines [ "{-# OPTIONS_GHC -Wtype-defaults #-}"
26132635
, "{-# LANGUAGE OverloadedStrings #-}"
@@ -2617,7 +2639,7 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
26172639
, ""
26182640
, "f a = traceShow (\"debug\" :: " <> listOfChar <> ") a"
26192641
])
2620-
, knownBrokenForGhcVersions [GHC92] "GHC 9.2 only has 'traceShow' in error span" $
2642+
, knownBrokenForGhcVersions [GHC92, GHC94] "GHC 9.2 only has 'traceShow' in error span" $
26212643
testSession "add default type to satisfy two constraints with duplicate literals" $
26222644
testFor
26232645
(T.unlines [ "{-# OPTIONS_GHC -Wtype-defaults #-}"
@@ -2628,7 +2650,11 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
26282650
, ""
26292651
, "f = seq (\"debug\" :: [Char]) (seq (\"debug\" :: [Char]) (traceShow \"debug\"))"
26302652
])
2653+
#if MIN_VERSION_ghc(9,4,0)
2654+
[ (DsWarning, (6, 54), "Defaulting the type variable") ]
2655+
#else
26312656
[ (DsWarning, (6, 54), "Defaulting the following constraint") ]
2657+
#endif
26322658
("Add type annotation ‘" <> listOfChar <> "’ to ‘\"debug\"")
26332659
(T.unlines [ "{-# OPTIONS_GHC -Wtype-defaults #-}"
26342660
, "{-# LANGUAGE OverloadedStrings #-}"
@@ -3245,15 +3271,15 @@ removeRedundantConstraintsTests = let
32453271
"Remove redundant constraints `(Monoid a, Show a)` from the context of the type signature for `foo`"
32463272
(typeSignatureSpaces $ Just "Monoid a, Show a")
32473273
(typeSignatureSpaces Nothing)
3248-
, check
3274+
, check
32493275
"Remove redundant constraint `Eq a` from the context of the type signature for `foo`"
32503276
typeSignatureLined1
32513277
typeSignatureOneLine
3252-
, check
3278+
, check
32533279
"Remove redundant constraints `(Eq a, Show a)` from the context of the type signature for `foo`"
32543280
typeSignatureLined2
32553281
typeSignatureOneLine
3256-
, check
3282+
, check
32573283
"Remove redundant constraint `Show a` from the context of the type signature for `foo`"
32583284
typeSignatureLined3
32593285
typeSignatureLined3'
@@ -4006,4 +4032,3 @@ assertJust s = \case
40064032
listOfChar :: T.Text
40074033
listOfChar | ghcVersion >= GHC90 = "String"
40084034
| otherwise = "[Char]"
4009-

0 commit comments

Comments
 (0)