summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc/Errors.hs
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2022-04-07 19:03:05 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-04-08 09:43:35 -0400
commit777365f18233d7ad032435ea2c93197cbb1d732e (patch)
tree059563b83d3ad3270a913cc834dfbbe8e2851e5d /compiler/GHC/Tc/Errors.hs
parentc44432db254d2fc960d7864e080cb50e65dfa7c6 (diff)
downloadhaskell-777365f18233d7ad032435ea2c93197cbb1d732e.tar.gz
Correctly report SrcLoc of redundant constraints
We were accidentally dropping the source location information in certain circumstances when reporting redundant constraints. This patch makes sure that we set the TcLclEnv correctly before reporting the warning. Fixes #21315
Diffstat (limited to 'compiler/GHC/Tc/Errors.hs')
-rw-r--r--compiler/GHC/Tc/Errors.hs19
1 files changed, 12 insertions, 7 deletions
diff --git a/compiler/GHC/Tc/Errors.hs b/compiler/GHC/Tc/Errors.hs
index 9b9eb8077b..f662495f2c 100644
--- a/compiler/GHC/Tc/Errors.hs
+++ b/compiler/GHC/Tc/Errors.hs
@@ -393,17 +393,22 @@ warnRedundantConstraints ctxt env info ev_vars
= return ()
| SigSkol user_ctxt _ _ <- info
- = restoreLclEnv env $ -- We want to add "In the type signature for f"
- -- to the error context, which is a bit tiresome
+ -- When dealing with a user-written type signature,
+ -- we want to add "In the type signature for f".
+ = restoreLclEnv env $
setSrcSpan (redundantConstraintsSpan user_ctxt) $
report_redundant_msg True
+ -- ^^^^ add "In the type signature..."
- | otherwise -- But for InstSkol there already *is* a surrounding
- -- "In the instance declaration for Eq [a]" context
- -- and we don't want to say it twice. Seems a bit ad-hoc
- = report_redundant_msg False
+ | otherwise
+ -- But for InstSkol there already *is* a surrounding
+ -- "In the instance declaration for Eq [a]" context
+ -- and we don't want to say it twice. Seems a bit ad-hoc
+ = restoreLclEnv env
+ $ report_redundant_msg False
+ -- ^^^^^ don't add "In the type signature..."
where
- report_redundant_msg :: Bool -- whether to add "In ..." to the diagnostic
+ report_redundant_msg :: Bool -- whether to add "In the type signature..." to the diagnostic
-> TcRn ()
report_redundant_msg show_info
= do { lcl_env <- getLclEnv