Skip to content
This repository was archived by the owner on Jan 2, 2021. It is now read-only.

Commit b76ef42

Browse files
authored
Ignore -Werror (#738)
* Ignore -Werror Fixes #735 * Compat with GHC < 8.8
1 parent 535e9bd commit b76ef42

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

session-loader/Development/IDE/Session.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ setOptions :: GhcMonad m => ComponentOptions -> DynFlags -> m (DynFlags, [Target
543543
setOptions (ComponentOptions theOpts compRoot _) dflags = do
544544
(dflags', targets) <- addCmdOpts theOpts dflags
545545
let dflags'' =
546+
disableWarningsAsErrors $
546547
-- disabled, generated directly by ghcide instead
547548
flip gopt_unset Opt_WriteInterface $
548549
-- disabled, generated directly by ghcide instead

src/Development/IDE/Core/Preprocessor.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ parsePragmasIntoDynFlags fp contents = catchSrcErrors "pragmas" $ do
145145
liftIO $ evaluate $ rnf opts
146146

147147
(dflags, _, _) <- parseDynamicFilePragma dflags0 opts
148-
return dflags
148+
return $ disableWarningsAsErrors dflags
149149

150150

151151
-- | Run (unlit) literate haskell preprocessor on a file, or buffer if set

src/Development/IDE/GHC/Compat.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ module Development.IDE.GHC.Compat(
4949
Module.addBootSuffix,
5050
pattern ModLocation,
5151
getConArgs,
52-
5352
HasSrcSpan,
5453
getLoc,
55-
5654
upNameCache,
55+
disableWarningsAsErrors,
5756

5857
module GHC,
5958
#if MIN_GHC_API_VERSION(8,6,0)
@@ -105,6 +104,7 @@ import GHC hiding (
105104
)
106105
import qualified HeaderInfo as Hdr
107106
import Avail
107+
import Data.List (foldl')
108108
import ErrUtils (ErrorMessages)
109109
import FastString (FastString)
110110

@@ -124,6 +124,7 @@ import System.FilePath ((-<.>))
124124
#endif
125125

126126
#if !MIN_GHC_API_VERSION(8,8,0)
127+
import qualified EnumSet
127128

128129
#if MIN_GHC_API_VERSION(8,6,0)
129130
import GhcPlugins (srcErrorMessages)
@@ -430,3 +431,13 @@ getConArgs = GHC.getConDetails
430431

431432
getPackageName :: DynFlags -> Module.InstalledUnitId -> Maybe PackageName
432433
getPackageName dfs i = packageName <$> lookupPackage dfs (Module.DefiniteUnitId (Module.DefUnitId i))
434+
435+
disableWarningsAsErrors :: DynFlags -> DynFlags
436+
disableWarningsAsErrors df =
437+
flip gopt_unset Opt_WarnIsError $ foldl' wopt_unset_fatal df [toEnum 0 ..]
438+
439+
#if !MIN_GHC_API_VERSION(8,8,0)
440+
wopt_unset_fatal :: DynFlags -> WarningFlag -> DynFlags
441+
wopt_unset_fatal dfs f
442+
= dfs { fatalWarningFlags = EnumSet.delete f (fatalWarningFlags dfs) }
443+
#endif

src/Development/IDE/GHC/Util.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Development.IDE.GHC.Util(
2929
hDuplicateTo',
3030
setHieDir,
3131
dontWriteHieFiles,
32+
disableWarningsAsErrors,
3233
) where
3334

3435
import Control.Concurrent

test/exe/Main.hs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,34 @@ diagnosticTests = testGroup "diagnostics"
469469
Lens.filtered (T.isInfixOf ("/" <> name <> ".hs:"))
470470
failure msg = liftIO $ assertFailure $ "Expected file path to be stripped but got " <> T.unpack msg
471471
Lens.mapMOf_ offenders failure notification
472+
, testSession' "-Werror in cradle is ignored" $ \sessionDir -> do
473+
liftIO $ writeFile (sessionDir </> "hie.yaml")
474+
"cradle: {direct: {arguments: [\"-Wall\", \"-Werror\"]}}"
475+
let fooContent = T.unlines
476+
[ "module Foo where"
477+
, "foo = ()"
478+
]
479+
_ <- createDoc "Foo.hs" "haskell" fooContent
480+
expectDiagnostics
481+
[ ( "Foo.hs"
482+
, [(DsWarning, (1, 0), "Top-level binding with no type signature:")
483+
]
484+
)
485+
]
486+
, testSessionWait "-Werror in pragma is ignored" $ do
487+
let fooContent = T.unlines
488+
[ "{-# OPTIONS_GHC -Wall -Werror #-}"
489+
, "module Foo() where"
490+
, "foo :: Int"
491+
, "foo = 1"
492+
]
493+
_ <- createDoc "Foo.hs" "haskell" fooContent
494+
expectDiagnostics
495+
[ ( "Foo.hs"
496+
, [(DsWarning, (3, 0), "Defined but not used:")
497+
]
498+
)
499+
]
472500
]
473501

474502
codeActionTests :: TestTree
@@ -3122,7 +3150,7 @@ mkRange :: Int -> Int -> Int -> Int -> Range
31223150
mkRange a b c d = Range (Position a b) (Position c d)
31233151

31243152
run :: Session a -> IO a
3125-
run s = withTempDir $ \dir -> runInDir dir s
3153+
run s = run' (const s)
31263154

31273155
runWithExtraFiles :: FilePath -> (FilePath -> Session a) -> IO a
31283156
runWithExtraFiles prefix s = withTempDir $ \dir -> do

0 commit comments

Comments
 (0)