Commit 7f2e0d67 authored by Jan Rasmus Tikovsky 's avatar Jan Rasmus Tikovsky
Browse files

Merge remote-tracking branch 'origin/WarnUnusedGlobalRefactoring'

Conflicts:
	test/TestFrontend.hs
parents e443351d 9bdf3d8c
......@@ -123,7 +123,7 @@ checkExports :: Maybe ExportSpec -> WCM () -- TODO checks
checkExports Nothing = ok
checkExports (Just (Exporting _ exports)) = do
mapM_ visitExport exports
reportUnusedVars
reportUnusedGlobalVars
where
visitExport (Export qid) = visitQId qid
visitExport _ = ok
......@@ -870,7 +870,13 @@ checkShadowing x = warnFor WarnNameShadowing $
shadowsVar x >>= maybe ok (report . warnShadowing x)
reportUnusedVars :: WCM ()
reportUnusedVars = warnFor WarnUnusedBindings $ do
reportUnusedVars = reportAllUnusedVars WarnUnusedBindings
reportUnusedGlobalVars :: WCM ()
reportUnusedGlobalVars = reportAllUnusedVars WarnUnusedGlobalBindings
reportAllUnusedVars :: WarnFlag -> WCM ()
reportAllUnusedVars wFlag = warnFor wFlag $ do
unused <- returnUnrefVars
unless (null unused) $ mapM_ report $ map warnUnrefVar unused
......
......@@ -153,39 +153,42 @@ data TargetType
-- |Warnings flags
data WarnFlag
= WarnMultipleImports -- ^ Warn for multiple imports
| WarnDisjoinedRules -- ^ Warn for disjoined function rules
| WarnUnusedBindings -- ^ Warn for unused bindings
| WarnNameShadowing -- ^ Warn for name shadowing
| WarnOverlapping -- ^ Warn for overlapping rules/alternatives
| WarnIncompletePatterns -- ^ Warn for incomplete pattern matching
| WarnMissingSignatures -- ^ Warn for missing type signatures
= WarnMultipleImports -- ^ Warn for multiple imports
| WarnDisjoinedRules -- ^ Warn for disjoined function rules
| WarnUnusedGlobalBindings -- ^ Warn for unused global bindings
| WarnUnusedBindings -- ^ Warn for unused local bindings
| WarnNameShadowing -- ^ Warn for name shadowing
| WarnOverlapping -- ^ Warn for overlapping rules/alternatives
| WarnIncompletePatterns -- ^ Warn for incomplete pattern matching
| WarnMissingSignatures -- ^ Warn for missing type signatures
deriving (Eq, Bounded, Enum, Show)
-- |Warning flags enabled by default
stdWarnFlags :: [WarnFlag]
stdWarnFlags =
[ WarnMultipleImports , WarnDisjoinedRules --, WarnUnusedBindings
, WarnNameShadowing , WarnOverlapping , WarnIncompletePatterns
, WarnMissingSignatures
[ WarnMultipleImports , WarnDisjoinedRules --, WarnUnusedGlobalBindings
, WarnUnusedBindings , WarnNameShadowing , WarnOverlapping
, WarnIncompletePatterns, WarnMissingSignatures
]
-- |Description and flag of warnings flags
warnFlags :: [(WarnFlag, String, String)]
warnFlags =
[ ( WarnMultipleImports , "multiple-imports"
[ ( WarnMultipleImports , "multiple-imports"
, "multiple imports" )
, ( WarnDisjoinedRules , "disjoined-rules"
, ( WarnDisjoinedRules , "disjoined-rules"
, "disjoined function rules" )
, ( WarnUnusedBindings , "unused-bindings"
, ( WarnUnusedGlobalBindings, "unused-global-bindings"
, "unused bindings" )
, ( WarnNameShadowing , "name-shadowing"
, ( WarnUnusedBindings , "unused-bindings"
, "unused bindings" )
, ( WarnNameShadowing , "name-shadowing"
, "name shadowing" )
, ( WarnOverlapping , "overlapping"
, ( WarnOverlapping , "overlapping"
, "overlapping function rules" )
, ( WarnIncompletePatterns, "incomplete-patterns"
, ( WarnIncompletePatterns , "incomplete-patterns"
, "incomplete pattern matching")
, ( WarnMissingSignatures , "missing-signatures"
, ( WarnMissingSignatures , "missing-signatures"
, "missing type signatures" )
]
......
......@@ -35,7 +35,7 @@ import Curry.Base.Message (Message, message, ppMessages, ppError)
import Curry.Base.Monad (CYIO, runCYIO)
import Curry.Base.Pretty (text)
import qualified CompilerOpts as CO ( Options (..), WarnOpts (..)
, Verbosity (VerbQuiet)
, WarnFlag (..), Verbosity (VerbQuiet)
, defaultOptions, defaultWarnOpts)
import CurryBuilder (buildCurry)
......@@ -50,7 +50,13 @@ runSecure act = runCYIO act `E.catch` handler
runTest :: CO.Options -> String -> [String] -> IO Progress
runTest opts test [] = passOrFail <$> runSecure (buildCurry opts' test)
where
opts' = opts { CO.optForce = True }
wOpts = CO.optWarnOpts opts
wFlags = CO.WarnUnusedBindings
: CO.WarnUnusedGlobalBindings
: CO.wnWarnFlags wOpts
opts' = opts { CO.optForce = True
, CO.optWarnOpts = wOpts { CO.wnWarnFlags = wFlags }
}
passOrFail = Finished . either fail pass
fail msgs
| null msgs = Pass
......@@ -58,8 +64,14 @@ runTest opts test [] = passOrFail <$> runSecure (buildCurry opts' test)
pass _ = Pass
runTest opts test errorMsgs = catchE <$> runSecure (buildCurry opts' test)
where
opts' = opts { CO.optForce = True }
catchE = Finished . either pass fail
wOpts = CO.optWarnOpts opts
wFlags = CO.WarnUnusedBindings
: CO.WarnUnusedGlobalBindings
: CO.wnWarnFlags wOpts
opts' = opts { CO.optForce = True
, CO.optWarnOpts = wOpts { CO.wnWarnFlags = wFlags }
}
catchE = Finished . either pass fail
pass msgs = let errorStr = showMessages msgs
leftOverMsgs = filter (not . flip isInfixOf errorStr) errorMsgs
in if null leftOverMsgs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment