Skip to content

Commit d669f53

Browse files
authored
Merge pull request #59 from hsenag/unqualified-warnings
Make sure warnings use unqualified names where appropriate
2 parents 4aa1821 + 316d78a commit d669f53

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Development/IDE/GHC/Warnings.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ withWarnings :: GhcMonad m => T.Text -> ((ModSummary -> ModSummary) -> m a) -> m
2929
withWarnings diagSource action = do
3030
warnings <- liftIO $ newVar []
3131
oldFlags <- getDynFlags
32-
let newAction dynFlags _ _ loc _ msg = do
33-
let d = diagFromErrMsg diagSource dynFlags $ mkPlainWarnMsg dynFlags loc msg
32+
let newAction :: DynFlags -> WarnReason -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
33+
newAction dynFlags _ _ loc style msg = do
34+
let d = diagFromErrMsg diagSource dynFlags $ mkWarnMsg dynFlags loc (queryQual style) msg
3435
modifyVar_ warnings $ return . (d:)
3536
setLogAction newAction
3637
res <- action $ \x -> x{ms_hspp_opts = (ms_hspp_opts x){log_action = newAction}}

test/exe/Main.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ diagnosticTests = testGroup "diagnostics"
206206
]
207207
)
208208
]
209+
, testSession "unqualified warnings" $ do
210+
let fooContent = T.unlines
211+
[ "{-# OPTIONS_GHC -Wredundant-constraints #-}"
212+
, "module Foo where"
213+
, "foo :: Ord a => a -> Int"
214+
, "foo a = 1"
215+
]
216+
_ <- openDoc' "Foo.hs" "haskell" fooContent
217+
expectDiagnostics
218+
[ ( "Foo.hs"
219+
-- The test is to make sure that warnings contain unqualified names
220+
-- where appropriate. The warning should use an unqualified name 'Ord', not
221+
-- sometihng like 'GHC.Classes.Ord'. The choice of redundant-constraints to
222+
-- test this is fairly arbitrary.
223+
, [(DsWarning, (2, 0), "Redundant constraint: Ord a")
224+
]
225+
)
226+
]
209227
]
210228

211229
codeActionTests :: TestTree

0 commit comments

Comments
 (0)