[Git][ghc/ghc][master] Suppress desugaring warnings in the pattern match checker
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: d419e972 by Luite Stegeman at 2026-04-13T15:16:04-04:00 Suppress desugaring warnings in the pattern match checker Avoid duplicating warnings from the actual desugaring pass. fixes #25996 - - - - - 5 changed files: - + changelog.d/fix-duplicate-pmc-warnings - compiler/GHC/HsToCore/Pmc/Desugar.hs - + testsuite/tests/deSugar/should_compile/T25996.hs - + testsuite/tests/deSugar/should_compile/T25996.stderr - testsuite/tests/deSugar/should_compile/all.T Changes: ===================================== changelog.d/fix-duplicate-pmc-warnings ===================================== @@ -0,0 +1,6 @@ +section: compiler +synopsis: Fix duplicate desugaring warnings emitted by the pattern match checker. + The pattern match checker now suppresses warnings that are already reported + by the main desugaring pass. +issues: #25996 +mrs: !15859 ===================================== compiler/GHC/HsToCore/Pmc/Desugar.hs ===================================== @@ -375,16 +375,18 @@ desugarConPatOut x con univ_tys ex_tvs dicts = \case desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM (PmPatBind Pre) -- See 'GrdPatBind' for how this simply repurposes GrdGRHS. -desugarPatBind loc var pat = +-- See Note [Suppress warnings in PMC desugaring] +desugarPatBind loc var pat = discardWarningsDs $ PmPatBind . flip PmGRHS (SrcInfo (L loc (ppr pat))) <$> desugarPat var pat desugarEmptyCase :: Id -> DsM PmEmptyCase desugarEmptyCase var = pure PmEmptyCase { pe_var = var } -- | Desugar the non-empty 'Match'es of a 'MatchGroup'. +-- See Note [Suppress warnings in PMC desugaring] desugarMatches :: [Id] -> NonEmpty (LMatch GhcTc (LHsExpr GhcTc)) -> DsM (PmMatchGroup Pre) -desugarMatches vars matches = +desugarMatches vars matches = discardWarningsDs $ PmMatchGroup <$> traverse (desugarMatch vars) matches -- Desugar a single match @@ -398,8 +400,9 @@ desugarMatch vars (L match_loc (Match { m_pats = L _ pats, m_grhss = grhss })) = -- tracePm "desugarMatch" (vcat [ppr pats, ppr pats', ppr grhss']) return PmMatch { pm_pats = pats', pm_grhss = grhss' } +-- See Note [Suppress warnings in PMC desugaring] desugarGRHSs :: SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM (PmGRHSs Pre) -desugarGRHSs match_loc pp_pats grhss = do +desugarGRHSs match_loc pp_pats grhss = discardWarningsDs $ do lcls <- desugarLocalBinds (grhssLocalBinds grhss) grhss' <- traverse (desugarLGRHS match_loc pp_pats) (grhssGRHSs grhss) return PmGRHSs { pgs_lcls = lcls, pgs_grhss = grhss' } @@ -593,6 +596,17 @@ The place to store the 'PmLet' guards for @where@ clauses (which are per 'GRHSs') is as a field of 'PmGRHSs'. For plain @let@ guards as in the guards of @x@, we can simply add them to the 'pg_grds' field of 'PmGRHS'. +Note [Suppress warnings in PMC desugaring] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This module uses 'dsLExpr', 'dsExpr', and 'dsSyntaxExpr' to desugar +expressions into Core for pattern match checking. The main desugaring +pass in GHC.HsToCore processes these same expressions too, so without +suppression any warnings would be emitted twice (#25996). + +To avoid this, the exported functions ('desugarPatBind', 'desugarMatches', +'desugarGRHSs') are wrapped in 'discardWarningsDs', covering all internal +desugarer calls without having to wrap each one individually. + Note [Desugaring -XStrict matches in Pmc] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider (#21761) ===================================== testsuite/tests/deSugar/should_compile/T25996.hs ===================================== @@ -0,0 +1,17 @@ +{-# OPTIONS_GHC -Wall #-} +{-# OPTIONS_GHC -Wno-unused-local-binds #-} +{-# OPTIONS_GHC -Wno-unused-top-binds #-} + +main :: IO () +main = do + pure () + where + biz :: IO () + biz = do + pure (10 :: Integer) + pure () + +biz' :: IO () +biz' = do + pure (10 :: Integer) + pure () ===================================== testsuite/tests/deSugar/should_compile/T25996.stderr ===================================== @@ -0,0 +1,10 @@ +T25996.hs:11:7: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)] + A do-notation statement discarded a result of type ‘Integer’ + Suggested fix: + Suppress this warning by saying ‘_ <- pure (10 :: Integer)’ + +T25996.hs:16:3: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)] + A do-notation statement discarded a result of type ‘Integer’ + Suggested fix: + Suppress this warning by saying ‘_ <- pure (10 :: Integer)’ + ===================================== testsuite/tests/deSugar/should_compile/all.T ===================================== @@ -115,3 +115,4 @@ test('T19883', normal, compile, ['']) test('T22719', normal, compile, ['-ddump-simpl -dsuppress-uniques -dno-typeable-binds']) test('T23550', normal, compile, ['']) test('T24489', normal, compile, ['-O']) +test('T25996', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d419e972dec4275afca69e7949d2f384... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d419e972dec4275afca69e7949d2f384... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Marge Bot (@marge-bot)