Commit 1e6ec124 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺 Committed by Ben Gamari

Fix misattribution of `-Wunused-local-binds` warnings

This fixes a bug where warnings actually controlled by

- `Opt_WarnUnusedMatches`
- `Opt_WarnUnusedTypePatterns`
- `Opt_WarnUnusedTopBinds`

were incorrectly reported as being controlled by
`Opt_WarnUnusedLocalBinds` as well

This bug was introduced in bb5afd3c
while implementing #10752

Test Plan: ./validate still running -- testsuite output wiggles expected

Reviewers: barrucadu, quchen, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2077
parent 2f3b8039
......@@ -2107,22 +2107,23 @@ warnUnusedTypePatterns = check_unused Opt_WarnUnusedTypePatterns
check_unused :: WarningFlag -> [Name] -> FreeVars -> RnM ()
check_unused flag bound_names used_names
= whenWOptM flag (warnUnusedLocals (filterOut (`elemNameSet` used_names) bound_names))
= whenWOptM flag (warnUnused flag (filterOut (`elemNameSet` used_names)
bound_names))
-------------------------
-- Helpers
warnUnusedGREs :: [GlobalRdrElt] -> RnM ()
warnUnusedGREs gres = mapM_ warnUnusedGRE gres
warnUnusedLocals :: [Name] -> RnM ()
warnUnusedLocals names = do
warnUnused :: WarningFlag -> [Name] -> RnM ()
warnUnused flag names = do
fld_env <- mkFieldEnv <$> getGlobalRdrEnv
mapM_ (warnUnusedLocal fld_env) names
mapM_ (warnUnused1 flag fld_env) names
warnUnusedLocal :: NameEnv (FieldLabelString, Name) -> Name -> RnM ()
warnUnusedLocal fld_env name
warnUnused1 :: WarningFlag -> NameEnv (FieldLabelString, Name) -> Name -> RnM ()
warnUnused1 flag fld_env name
= when (reportable name) $
addUnusedWarning Opt_WarnUnusedLocalBinds
addUnusedWarning flag
occ (nameSrcSpan name)
(text "Defined but not used")
where
......@@ -2133,7 +2134,7 @@ warnUnusedLocal fld_env name
warnUnusedGRE :: GlobalRdrElt -> RnM ()
warnUnusedGRE gre@(GRE { gre_name = name, gre_lcl = lcl, gre_imp = is })
| lcl = do fld_env <- mkFieldEnv <$> getGlobalRdrEnv
warnUnusedLocal fld_env name
warnUnused1 Opt_WarnUnusedTopBinds fld_env name
| otherwise = when (reportable name) (mapM_ warn is)
where
occ = greOccName gre
......
ds053.hs:5:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
ds053.hs:5:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘f’
......@@ -13,7 +13,7 @@ werror.hs:8:1: warning: [-Wtabs (in -Wdefault)]
Tab character found here.
Please use spaces instead.
werror.hs:10:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
werror.hs:10:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘f’
werror.hs:10:1: warning: [-Wmissing-signatures (in -Wall)]
......
UnusedTyVarWarnings.hs:8:5: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
UnusedTyVarWarnings.hs:8:5: warning: [-Wunused-type-patterns]
Defined but not used: type variable ‘b’
UnusedTyVarWarnings.hs:11:18: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
UnusedTyVarWarnings.hs:11:18: warning: [-Wunused-type-patterns]
Defined but not used: type variable ‘b’
UnusedTyVarWarnings.hs:27:5: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
UnusedTyVarWarnings.hs:27:5: warning: [-Wunused-type-patterns]
Defined but not used: type variable ‘a’
UnusedTyVarWarnings.hs:33:17: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
UnusedTyVarWarnings.hs:33:17: warning: [-Wunused-type-patterns]
Defined but not used: type variable ‘b’
UnusedTyVarWarningsNamedWCs.hs:8:5: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
UnusedTyVarWarningsNamedWCs.hs:8:5: warning: [-Wunused-type-patterns]
Defined but not used: type variable ‘b’
UnusedTyVarWarningsNamedWCs.hs:11:18: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
UnusedTyVarWarningsNamedWCs.hs:11:18: warning: [-Wunused-type-patterns]
Defined but not used: type variable ‘b’
UnusedTyVarWarningsNamedWCs.hs:27:5: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
UnusedTyVarWarningsNamedWCs.hs:27:5: warning: [-Wunused-type-patterns]
Defined but not used: type variable ‘a’
UnusedTyVarWarningsNamedWCs.hs:33:17: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
UnusedTyVarWarningsNamedWCs.hs:33:17: warning: [-Wunused-type-patterns]
Defined but not used: type variable ‘b’
overloadedrecfldsfail05.hs:7:16: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
overloadedrecfldsfail05.hs:7:16: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘foo’
<no location info>: error:
......
[1 of 2] Compiling OverloadedRecFldsFail06_A ( OverloadedRecFldsFail06_A.hs, OverloadedRecFldsFail06_A.o )
OverloadedRecFldsFail06_A.hs:9:15: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
OverloadedRecFldsFail06_A.hs:9:15: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: data constructor ‘MkUnused’
OverloadedRecFldsFail06_A.hs:9:42: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
OverloadedRecFldsFail06_A.hs:9:42: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘unused2’
OverloadedRecFldsFail06_A.hs:9:59: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
OverloadedRecFldsFail06_A.hs:9:59: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘used_locally’
[2 of 2] Compiling Main ( overloadedrecfldsfail06.hs, overloadedrecfldsfail06.o )
......
......@@ -3,7 +3,7 @@ read014.hs:4:1: warning: [-Wmissing-signatures (in -Wall)]
Top-level binding with no type signature:
ng1 :: forall t a. Num a => t -> a -> a
read014.hs:4:5: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
read014.hs:4:5: warning: [-Wunused-matches (in -Wextra)]
Defined but not used: ‘x’
read014.hs:6:10: warning: [-Wmissing-methods (in -Wdefault)]
......@@ -11,5 +11,5 @@ read014.hs:6:10: warning: [-Wmissing-methods (in -Wdefault)]
‘+’, ‘*’, ‘abs’, ‘signum’, and ‘fromInteger’
• In the instance declaration for ‘Num (a, b)’
read014.hs:8:53: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
read014.hs:8:53: warning: [-Wunused-matches (in -Wextra)]
Defined but not used: ‘x’
T17a.hs:8:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
T17a.hs:8:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘top’
T17d.hs:14:5: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
T17d.hs:14:5: warning: [-Wunused-matches (in -Wextra)]
Defined but not used: ‘match’
T17e.hs:8:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
T17e.hs:8:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘top’
T17e.hs:11:11: warning: [-Wunused-pattern-binds (in -Wextra, -Wunused-binds)]
......
T3371.hs:10:14: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
T3371.hs:10:14: warning: [-Wunused-matches (in -Wextra)]
Defined but not used: ‘a’
T3449.hs-boot:8:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
T3449.hs-boot:8:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘unused’
T7145b.hs:7:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
T7145b.hs:7:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘pure’
mc10.hs:14:11: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
mc10.hs:14:11: warning: [-Wunused-matches (in -Wextra)]
Defined but not used: ‘y’
rn040.hs:6:12: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
rn040.hs:6:12: warning: [-Wunused-matches (in -Wextra)]
Defined but not used: ‘y’
rn040.hs:8:8: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
rn040.hs:8:8: warning: [-Wunused-matches (in -Wextra)]
Defined but not used: ‘w’
rn041.hs:7:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
rn041.hs:7:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘f’
rn041.hs:9:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
rn041.hs:9:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘g’
rn041.hs:10:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
rn041.hs:10:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘h’
rn047.hs:12:11: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
rn047.hs:12:11: warning: [-Wunused-matches (in -Wextra)]
Defined but not used: ‘y’
T2497.hs:22:1: warning: [-Wunused-local-binds (in -Wextra, -Wunused-binds)]
T2497.hs:22:1: warning: [-Wunused-top-binds (in -Wextra, -Wunused-binds)]
Defined but not used: ‘beq’
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