on master help sign in
Make sure warnings use unqualified names where appropriate

Because we are constructing the message objects ourselves, as opposed to error messages which are constructed by GHC, we need to take care to respect the passed-in 'PprStyle'.

commit316d78a4715ba85f75dc714bcb5f3ea0c03b15b7 authorGanesh Sittampalam <ganesh@earth.li> dateFri 13 Sep 2019, 13:20 (7 years ago) parent4aa1821
2 files changed+21−2
src/Development/IDE/GHC/Warnings.hs+3−2 test/exe/Main.hs+18
src/Development/IDE/GHC/Warnings.hs+3−2
@@ -29,8 +29,9 @@ withWarnings :: GhcMonad m => T.Text -> ((ModSummary -> ModSummary) -> m a) -> m
2929withWarnings 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+18
@@ -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
211229codeActionTests :: TestTree