Sebastian Graf pushed to branch wip/T28014 at Glasgow Haskell Compiler / GHC

Commits:

10 changed files:

Changes:

  • changelog.d/28014
    1
    +section: compiler
    
    2
    +synopsis: The pattern-match checker no longer assumes that pattern synonym matches force their argument
    
    3
    +description:
    
    4
    +  A match on a pattern synonym excludes ⊥ as a value of the scrutinee only
    
    5
    +  through a ``COMPLETE`` set: when every member that can match at the type of
    
    6
    +  the scrutinee failed to match, and that type has a value other than ⊥.
    
    7
    +  Hence ``-Wredundant-bang-patterns`` and ``-Woverlapping-patterns`` no longer
    
    8
    +  report bangs or clauses as redundant or inaccessible when deleting them
    
    9
    +  would change the semantics, and ``-Wincomplete-patterns`` reports matches
    
    10
    +  that fail on ⊥ fields that a pattern synonym does not force. Redundancy that
    
    11
    +  rests on the strictness of a pattern synonym outside of an exhausted
    
    12
    +  ``COMPLETE`` set is no longer reported.
    
    13
    +issues: #28014 #17357
    
    14
    +mrs: !17033

  • compiler/GHC/HsToCore/Pmc/Check.hs
    ... ... @@ -144,7 +144,7 @@ checkGrd grd = CA $ \inc -> case grd of
    144 144
                             , cr_approx = Precise }
    
    145 145
       -- Con: Fall through on x ≁ K and refine with x ~ K ys and type info
    
    146 146
       PmCon x con tvs dicts args -> do
    
    147
    -    !div <- if isPmAltConMatchStrict con
    
    147
    +    !div <- if pmAltConMatchMayDiverge con
    
    148 148
           then addPhiCtNablas inc (PhiBotCt x)
    
    149 149
           else pure mempty
    
    150 150
         !matched <- addPhiCtNablas inc (PhiConCt x con tvs (map evVarPred dicts) args)
    

  • compiler/GHC/HsToCore/Pmc/Solver.hs
    ... ... @@ -547,6 +547,116 @@ clause as redundant, which clearly is unsound. The solution:
    547 547
     3. Immediately reject when we find @x ≁ T2@.
    
    548 548
     Handling of Newtypes is also described in the Appendix of the Lower Your Guards paper,
    
    549 549
     where you can find the solution in a perhaps more digestible format.
    
    550
    +
    
    551
    +Note [Strictness of pattern synonym matches]
    
    552
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    553
    +TODO(sgraf): formulate. Points:
    
    554
    +
    
    555
    +* A match on a data constructor K forces x, so both x ~ K and x ≁ K imply
    
    556
    +  x ≁ ⊥. A match on a pattern synonym P need not force x (#28014, #17357):
    
    557
    +
    
    558
    +    pattern F :: a
    
    559
    +    pattern F <- (const False -> True)
    
    560
    +
    
    561
    +    withBang :: Bool -> Int
    
    562
    +    withBang F  = 1
    
    563
    +    withBang !_ = 2   -- Bang not redundant: withBang undefined is ⊥,
    
    564
    +                      -- but 2 without the bang
    
    565
    +
    
    566
    +  So neither x ~ P nor x ≁ P implies x ≁ ⊥ ('isPmAltConMatchStrict').
    
    567
    +
    
    568
    +* A match on P may still diverge on ⊥, so the divergent set gets x ~ ⊥
    
    569
    +  ('pmAltConMatchMayDiverge'). Example from #17357:
    
    570
    +
    
    571
    +    strictConst :: a -> b -> a
    
    572
    +    strictConst a b = seq b a
    
    573
    +    pattern SF <- (strictConst False -> True)
    
    574
    +
    
    575
    +    f2 :: Bool -> Bool -> ()
    
    576
    +    f2 _  True = ()
    
    577
    +    f2 SF True = ()   -- Inaccessible RHS, not redundant
    
    578
    +    f2 !_ True = ()
    
    579
    +    f2 _  _    = ()
    
    580
    +
    
    581
    +* Rule. Let C be a COMPLETE set from a pragma that applies at the type τ
    
    582
    +  of x. If x failed to match a member of C, and no member of C can match x,
    
    583
    +  then x ≁ ⊥. A member P cannot match x when x failed to match P, or when the
    
    584
    +  provided constraints of P contradict τ. The pragma asserts that matching
    
    585
    +  any value of τ, ⊥ included, against the members of C succeeds or diverges.
    
    586
    +  x ≁ ⊥ is a fact, so redundancy and coverage both use it.
    
    587
    +
    
    588
    +* Type constraints alone leave ⊥. Here no member of C = {G1, G2} (below)
    
    589
    +  can match at G Char, and x failed to match only F:
    
    590
    +
    
    591
    +    data U = MkU (G Char)
    
    592
    +    hc :: U -> Int
    
    593
    +    hc (MkU F) = 1     -- Not matched: MkU _
    
    594
    +
    
    595
    +* Matcher lemma, for the pragma assertion at a τ with a non-⊥ value.
    
    596
    +  $mP :: forall r. τ -> (args -> r) -> (Void# -> r) -> r.
    
    597
    +  By parametricity, $mP v k e ∈ {⊥, k args, e (##)}. By monotonicity in v,
    
    598
    +  if P fails on ⊥ without diverging, P fails on every value.
    
    599
    +  A non-⊥ value v of τ matches some member P of C. If P failed on ⊥
    
    600
    +  without diverging, P fails on v. Contradiction.
    
    601
    +
    
    602
    +* The vanilla COMPLETE set of a data type needs no rule. A failed match on a
    
    603
    +  data constructor gives x ≁ ⊥ already. If no data constructor failed but
    
    604
    +  the set has no inhabitant, τ has no data constructor, and ⊥ stays:
    
    605
    +
    
    606
    +    data T = MkT Void
    
    607
    +    h :: T -> Int
    
    608
    +    h (MkT F) = 1      -- Not matched: MkT _. Indeed h (MkT undefined) fails.
    
    609
    +
    
    610
    +* Implementation in the inhabitation test ('instantiate'). A residual
    
    611
    +  COMPLETE set from a pragma that lost a member witnesses a failed match on
    
    612
    +  that member ('matchedPragmaSets'). This covers synonyms with a required
    
    613
    +  theta, which are not in 'vi_neg'
    
    614
    +  (Note [Completeness checking with required Thetas]).
    
    615
    +  - Without such a set, offer ⊥ first, as before.
    
    616
    +  - Otherwise, search the residual COMPLETE sets for a non-⊥ inhabitant
    
    617
    +    ('instCompleteSets'). If there is none, offer ⊥ when each of these sets
    
    618
    +    has an inhabitant ('allInhabited').
    
    619
    +  The order is only a matter of performance
    
    620
    +  (Note [Shortcutting the inhabitation test]).
    
    621
    +  'generateInhabitingPatterns' decides on a wildcard the same way.
    
    622
    +  Wrinkle: 'instCompleteSet' also removes a member that cannot match at the
    
    623
    +  type of x at the time of the test. A later type refinement that rules out
    
    624
    +  the remaining members then rules out ⊥ as well.
    
    625
    +
    
    626
    +* Example: every member failed.
    
    627
    +
    
    628
    +    pattern Nil :: [a]
    
    629
    +    pattern Nil <- (null -> True)
    
    630
    +    pattern Cons :: a -> [a] -> [a]
    
    631
    +    pattern Cons x xs <- (uncons -> Just (x, xs))
    
    632
    +    {-# COMPLETE Nil, Cons #-}
    
    633
    +
    
    634
    +    g :: [a] -> Int
    
    635
    +    g Nil        = 0
    
    636
    +    g (Cons _ _) = 1   -- Exhaustive
    
    637
    +    g _          = 2   -- Redundant
    
    638
    +
    
    639
    +* Example: members that cannot match at τ.
    
    640
    +
    
    641
    +    data G a where { G1' :: G Int; G2' :: G Bool }
    
    642
    +    pattern G1 :: () => (a ~ Int) => G a
    
    643
    +    pattern G1 = G1'
    
    644
    +    pattern G2 :: () => (a ~ Bool) => G a
    
    645
    +    pattern G2 = G2'
    
    646
    +    {-# COMPLETE G1, G2 #-}
    
    647
    +
    
    648
    +    fb :: G Int -> Int
    
    649
    +    fb G1 = 1          -- Exhaustive: G2 cannot match at G Int
    
    650
    +
    
    651
    +* Precision loss: redundancy that rests on the strictness of P outside an
    
    652
    +  exhausted COMPLETE set is not reported.
    
    653
    +
    
    654
    +    pattern J :: a -> Maybe a
    
    655
    +    pattern J x = Just x
    
    656
    +
    
    657
    +    k :: Maybe Int -> Int
    
    658
    +    k (J _) = 1
    
    659
    +    k !_    = 2        -- Bang is dead, but not reported
    
    550 660
     -}
    
    551 661
     
    
    552 662
     -------------------------
    
    ... ... @@ -729,7 +839,7 @@ addNotConCt nabla x nalt = do
    729 839
         -- otherwise return updated entry and `Just x'` if `x` should be marked dirty,
    
    730 840
         -- where `x'` is the representative of `x`.
    
    731 841
         go :: VarInfo -> MaybeT DsM (Maybe Id, VarInfo)
    
    732
    -    go vi@(VI x' pos neg _ rcm) = do
    
    842
    +    go vi@(VI x' pos neg bot rcm) = do
    
    733 843
           -- 1. Bail out quickly when nalt contradicts a solution
    
    734 844
           let contradicts nalt sol = eqPmAltCon (paca_con sol) nalt == Equal
    
    735 845
           guard (not (any (contradicts nalt) pos))
    
    ... ... @@ -741,8 +851,10 @@ addNotConCt nabla x nalt = do
    741 851
                 -- See Note [Completeness checking with required Thetas]
    
    742 852
                 | hasRequiredTheta nalt  = neg
    
    743 853
                 | otherwise              = extendPmAltConSet neg nalt
    
    744
    -      massert (isPmAltConMatchStrict nalt)
    
    745
    -      let vi' = vi{ vi_neg = neg', vi_bot = IsNotBot }
    
    854
    +      -- See Note [Strictness of pattern synonym matches]
    
    855
    +      let bot' | isPmAltConMatchStrict nalt = IsNotBot
    
    856
    +               | otherwise                  = bot
    
    857
    +      let vi' = vi{ vi_neg = neg', vi_bot = bot' }
    
    746 858
           -- 3. Make sure there's at least one other possible constructor
    
    747 859
           mb_rcm' <- lift (markMatched nalt rcm)
    
    748 860
           pure $ case mb_rcm' of
    
    ... ... @@ -796,8 +908,9 @@ addConCt nabla@MkNabla{ nabla_tm_st = ts@TmSt{ ts_facts=env } } x alt tvs args =
    796 908
                 MaybeBot -> pure (nabla_with MaybeBot)
    
    797 909
                 IsBot    -> addBotCt (nabla_with MaybeBot) y
    
    798 910
                 IsNotBot -> addNotBotCt (nabla_with MaybeBot) y
    
    799
    -        _ -> assert (isPmAltConMatchStrict alt )
    
    800
    -             pure (nabla_with IsNotBot) -- strict match ==> not ⊥
    
    911
    +        _ | isPmAltConMatchStrict alt -> pure (nabla_with IsNotBot) -- strict match ==> not ⊥
    
    912
    +          -- See Note [Strictness of pattern synonym matches]
    
    913
    +          | otherwise                 -> pure (nabla_with bot)
    
    801 914
     
    
    802 915
     equateTys :: [Type] -> [Type] -> [PhiCt]
    
    803 916
     equateTys ts us =
    
    ... ... @@ -1372,8 +1485,31 @@ varNeedsTesting old_ty_st MkNabla{nabla_ty_st=new_ty_st} vi = do
    1372 1485
     --     remain that do not satisfy it.  This lazy approach just
    
    1373 1486
     --     avoids doing unnecessary work.
    
    1374 1487
     instantiate :: Int -> Nabla -> VarInfo -> MaybeT DsM VarInfo
    
    1375
    -instantiate fuel nabla vi = {-# SCC "instantiate" #-}
    
    1376
    -  (instBot fuel nabla vi <|> instCompleteSets fuel nabla vi)
    
    1488
    +instantiate fuel nabla vi = {-# SCC "instantiate" #-} do
    
    1489
    +  -- See Note [Strictness of pattern synonym matches]
    
    1490
    +  matched <- lift (matchedPragmaSets vi)
    
    1491
    +  if null matched
    
    1492
    +    then instBot fuel nabla vi <|> instCompleteSets fuel nabla vi
    
    1493
    +    else instCompleteSets fuel nabla vi <|> do
    
    1494
    +      guard =<< lift (allInhabited fuel nabla (vi_id vi) matched)
    
    1495
    +      instBot fuel nabla vi
    
    1496
    +
    
    1497
    +-- | The residual COMPLETE sets from pragmas that lost a member, for a variable
    
    1498
    +-- that might be ⊥. When one of them has no inhabitant, the variable is not ⊥.
    
    1499
    +-- See Note [Strictness of pattern synonym matches].
    
    1500
    +matchedPragmaSets :: VarInfo -> DsM DsCompleteMatches
    
    1501
    +matchedPragmaSets VI{ vi_bot = IsNotBot } = pure []
    
    1502
    +matchedPragmaSets VI{ vi_rcm = rcm } = case rcm_pragmas rcm of
    
    1503
    +  Nothing        -> pure []
    
    1504
    +  Just residuals -> do
    
    1505
    +    originals <- dsGetCompleteMatches
    
    1506
    +    let lost_member orig res = sizeUniqDSet (cmConLikes res) < sizeUniqDSet (cmConLikes orig)
    
    1507
    +    pure [ res | (orig, res) <- zip originals residuals, lost_member orig res ]
    
    1508
    +
    
    1509
    +-- | Whether each of the COMPLETE sets has an inhabitant at the variable.
    
    1510
    +allInhabited :: Int -> Nabla -> Id -> DsCompleteMatches -> DsM Bool
    
    1511
    +allInhabited fuel nabla x cms =
    
    1512
    +  isJust <$> runMaybeT (foldM (\nabla cm -> instCompleteSet fuel nabla x cm) nabla cms)
    
    1377 1513
     
    
    1378 1514
     -- | The \(⊢_{Bot}\) rule from the paper
    
    1379 1515
     instBot :: Int -> Nabla -> VarInfo -> MaybeT DsM VarInfo
    
    ... ... @@ -1986,7 +2122,11 @@ generateInhabitingPatterns mode (x:xs) n nabla = do
    1986 2122
                 Just clss -> do
    
    1987 2123
                   -- Try each COMPLETE set.
    
    1988 2124
                   nablass' <- forM clss (instantiate_cons y rep_ty xs n newty_nabla)
    
    1989
    -              if any null nablass' && vi_bot vi /= IsNotBot
    
    2125
    +              -- See Note [Strictness of pattern synonym matches]
    
    2126
    +              bot_possible <- if any null nablass' && vi_bot vi /= IsNotBot
    
    2127
    +                then matchedPragmaSets vi >>= allInhabited initFuel newty_nabla y
    
    2128
    +                else pure False
    
    2129
    +              if bot_possible
    
    1990 2130
                   then generateInhabitingPatterns mode xs n newty_nabla -- bot is still possible. Display a wildcard!
    
    1991 2131
                   else do
    
    1992 2132
                     -- Pick the residual COMPLETE set with the smallest cost (see 'completeSetCost').
    

  • compiler/GHC/HsToCore/Pmc/Solver/Types.hs
    ... ... @@ -22,7 +22,7 @@ module GHC.HsToCore.Pmc.Solver.Types (
    22 22
     
    
    23 23
             -- ** Representations for Literals and AltCons
    
    24 24
             PmLit(..), PmLitValue(..), PmAltCon(..), pmLitType, pmAltConType,
    
    25
    -        isPmAltConMatchStrict, pmAltConImplBangs,
    
    25
    +        isPmAltConMatchStrict, pmAltConMatchMayDiverge, pmAltConImplBangs,
    
    26 26
     
    
    27 27
             -- *** PmAltConSet
    
    28 28
             PmAltConSet, emptyPmAltConSet, isEmptyPmAltConSet, elemPmAltConSet,
    
    ... ... @@ -586,14 +586,23 @@ pmAltConType (PmAltLit lit) _arg_tys = assert (null _arg_tys ) $ pmLitType l
    586 586
     pmAltConType (PmAltConLike con) arg_tys  = conLikeResTy con arg_tys
    
    587 587
     
    
    588 588
     -- | Is a match on this constructor forcing the match variable?
    
    589
    --- True of data constructors, literals and pattern synonyms (#17357), but not of
    
    590
    --- newtypes.
    
    591
    --- See Note [Coverage checking Newtype matches] in GHC.HsToCore.Pmc.Solver.
    
    589
    +-- True of data constructors and literals, but not of newtypes and pattern
    
    590
    +-- synonyms.
    
    591
    +-- See Note [Coverage checking Newtype matches] and
    
    592
    +-- Note [Strictness of pattern synonym matches] in GHC.HsToCore.Pmc.Solver.
    
    592 593
     isPmAltConMatchStrict :: PmAltCon -> Bool
    
    593 594
     isPmAltConMatchStrict PmAltLit{}                      = True
    
    594
    -isPmAltConMatchStrict (PmAltConLike PatSynCon{})      = True -- #17357
    
    595
    +isPmAltConMatchStrict (PmAltConLike PatSynCon{})      = False
    
    595 596
     isPmAltConMatchStrict (PmAltConLike (RealDataCon dc)) = not (isNewDataCon dc)
    
    596 597
     
    
    598
    +-- | Can a match on this constructor diverge when the match variable is ⊥?
    
    599
    +-- True of everything but newtypes.
    
    600
    +-- See Note [Coverage checking Newtype matches] and
    
    601
    +-- Note [Strictness of pattern synonym matches] in GHC.HsToCore.Pmc.Solver.
    
    602
    +pmAltConMatchMayDiverge :: PmAltCon -> Bool
    
    603
    +pmAltConMatchMayDiverge (PmAltConLike (RealDataCon dc)) = not (isNewDataCon dc)
    
    604
    +pmAltConMatchMayDiverge _                               = True
    
    605
    +
    
    597 606
     pmAltConImplBangs :: PmAltCon -> [HsImplBang]
    
    598 607
     pmAltConImplBangs PmAltLit{}         = []
    
    599 608
     pmAltConImplBangs (PmAltConLike con) = conLikeImplBangs con
    

  • testsuite/tests/pmcheck/should_compile/T17357.stderr
    1
    -
    
    2
    -T17357.hs:22:1: warning: [-Woverlapping-patterns (in -Wdefault)]
    
    1
    +T17357.hs:22:1: warning: [GHC-94210] [-Woverlapping-patterns (in -Wdefault)]
    
    3 2
         Pattern match has inaccessible right hand side
    
    4 3
         In an equation for ‘f’: f F True = ...
    
    5 4
     
    
    6
    -T17357.hs:23:1: warning: [-Woverlapping-patterns (in -Wdefault)]
    
    5
    +T17357.hs:23:1: warning: [GHC-94210] [-Woverlapping-patterns (in -Wdefault)]
    
    7 6
         Pattern match has inaccessible right hand side
    
    8 7
         In an equation for ‘f’: f !_ True = ...
    
    9 8
     
    
    10
    -T17357.hs:30:1: warning: [-Woverlapping-patterns (in -Wdefault)]
    
    9
    +T17357.hs:30:1: warning: [GHC-94210] [-Woverlapping-patterns (in -Wdefault)]
    
    11 10
         Pattern match has inaccessible right hand side
    
    12 11
         In an equation for ‘f2’: f2 SF True = ...
    
    13 12
     
    
    14
    -T17357.hs:31:1: warning: [-Woverlapping-patterns (in -Wdefault)]
    
    13
    +T17357.hs:31:1: warning: [GHC-94210] [-Woverlapping-patterns (in -Wdefault)]
    
    15 14
         Pattern match has inaccessible right hand side
    
    16 15
         In an equation for ‘f2’: f2 !_ True = ...
    
    17 16
     
    
    18
    -T17357.hs:42:1: warning: [-Woverlapping-patterns (in -Wdefault)]
    
    17
    +T17357.hs:42:1: warning: [GHC-53633] [-Woverlapping-patterns (in -Wdefault)]
    
    19 18
         Pattern match is redundant
    
    20 19
         In an equation for ‘f3’: f3 !_ = ...
    
    20
    +

  • testsuite/tests/pmcheck/should_compile/T28014.hs
    1
    +{-# LANGUAGE BangPatterns, GADTs, PatternSynonyms, ViewPatterns #-}
    
    2
    +module T28014 where
    
    3
    +
    
    4
    +import Data.List (uncons)
    
    5
    +import Data.Void
    
    6
    +
    
    7
    +-- | Never matches, and does not force its argument.
    
    8
    +pattern F :: a
    
    9
    +pattern F <- (const False -> True)
    
    10
    +
    
    11
    +-- | The bang is not redundant: withBang undefined is ⊥, but would be 2
    
    12
    +-- without the bang.
    
    13
    +withBang :: Bool -> Int
    
    14
    +withBang F  = 1
    
    15
    +withBang !_ = 2
    
    16
    +
    
    17
    +data T = MkT Void
    
    18
    +
    
    19
    +-- | Not exhaustive: h (MkT undefined) fails to match.
    
    20
    +h :: T -> Int
    
    21
    +h (MkT F) = 1
    
    22
    +
    
    23
    +pattern Nil :: [a]
    
    24
    +pattern Nil <- (null -> True)
    
    25
    +pattern Cons :: a -> [a] -> [a]
    
    26
    +pattern Cons x xs <- (uncons -> Just (x, xs))
    
    27
    +{-# COMPLETE Nil, Cons #-}
    
    28
    +
    
    29
    +-- | Exhaustive, and the last clause is redundant.
    
    30
    +g :: [a] -> Int
    
    31
    +g Nil        = 0
    
    32
    +g (Cons _ _) = 1
    
    33
    +g _          = 2
    
    34
    +
    
    35
    +-- | The last clause is redundant.
    
    36
    +gBang :: [a] -> Int
    
    37
    +gBang Nil        = 0
    
    38
    +gBang (Cons _ _) = 1
    
    39
    +gBang !_         = 2
    
    40
    +
    
    41
    +data G a where
    
    42
    +  G1' :: G Int
    
    43
    +  G2' :: G Bool
    
    44
    +
    
    45
    +pattern G1 :: () => (a ~ Int) => G a
    
    46
    +pattern G1 = G1'
    
    47
    +pattern G2 :: () => (a ~ Bool) => G a
    
    48
    +pattern G2 = G2'
    
    49
    +{-# COMPLETE G1, G2 #-}
    
    50
    +
    
    51
    +-- | Exhaustive: G2 cannot match at G Int.
    
    52
    +fb :: G Int -> Int
    
    53
    +fb G1 = 1
    
    54
    +
    
    55
    +data U = MkU (G Char)
    
    56
    +
    
    57
    +-- | Exhaustive, by the COMPLETE pragma.
    
    58
    +hu :: U -> Int
    
    59
    +hu (MkU G1) = 1
    
    60
    +
    
    61
    +-- | Not exhaustive: no member of the COMPLETE set for G can match at G Char,
    
    62
    +-- and hc (MkU F) fails on MkU undefined.
    
    63
    +hc :: U -> Int
    
    64
    +hc (MkU F) = 1
    
    65
    +
    
    66
    +-- | E Int has no constructor.
    
    67
    +data E a where
    
    68
    +  E1 :: E Bool
    
    69
    +
    
    70
    +-- | No clause is inaccessible: w undefined G1' is 2.
    
    71
    +w :: E a -> G a -> Int
    
    72
    +w F _   = 1
    
    73
    +w _ G1' = 2
    
    74
    +w _ G2' = 3
    
    75
    +
    
    76
    +pattern J :: a -> Maybe a
    
    77
    +pattern J x = Just x
    
    78
    +
    
    79
    +-- | The bang is dead, but the checker can't see that J forces its argument.
    
    80
    +k :: Maybe Int -> Int
    
    81
    +k (J _) = 1
    
    82
    +k !_    = 2

  • testsuite/tests/pmcheck/should_compile/T28014.stderr
    1
    +T28014.hs:21:1: warning: [GHC-62161] [-Wincomplete-patterns (in -Wextra)]
    
    2
    +    Pattern match(es) are non-exhaustive
    
    3
    +    In an equation for ‘h’:
    
    4
    +        Patterns of type ‘T’ not matched: MkT p where p is not one of {F}
    
    5
    +
    
    6
    +T28014.hs:33:1: warning: [GHC-53633] [-Woverlapping-patterns (in -Wdefault)]
    
    7
    +    Pattern match is redundant
    
    8
    +    In an equation for ‘g’: g _ = ...
    
    9
    +
    
    10
    +T28014.hs:39:1: warning: [GHC-53633] [-Woverlapping-patterns (in -Wdefault)]
    
    11
    +    Pattern match is redundant
    
    12
    +    In an equation for ‘gBang’: gBang !_ = ...
    
    13
    +
    
    14
    +T28014.hs:59:1: warning: [GHC-94210] [-Woverlapping-patterns (in -Wdefault)]
    
    15
    +    Pattern match has inaccessible right hand side
    
    16
    +    In an equation for ‘hu’: hu (MkU G1) = ...
    
    17
    +
    
    18
    +T28014.hs:59:9: warning: [GHC-40564] [-Winaccessible-code (in -Wdefault)]
    
    19
    +    • Inaccessible code in
    
    20
    +        a pattern with pattern synonym:
    
    21
    +          G1 :: forall a. () => (a ~ Int) => G a,
    
    22
    +        in an equation for ‘hu’
    
    23
    +      Couldn't match type ‘Char’ with ‘Int’
    
    24
    +    • In the pattern: G1
    
    25
    +      In the pattern: MkU G1
    
    26
    +      In an equation for ‘hu’: hu (MkU G1) = 1
    
    27
    +
    
    28
    +T28014.hs:64:1: warning: [GHC-62161] [-Wincomplete-patterns (in -Wextra)]
    
    29
    +    Pattern match(es) are non-exhaustive
    
    30
    +    In an equation for ‘hc’:
    
    31
    +        Patterns of type ‘U’ not matched: MkU p where p is not one of {F}
    
    32
    +

  • testsuite/tests/pmcheck/should_compile/T28014b.hs
    1
    +{-# LANGUAGE GADTs, PatternSynonyms, ViewPatterns #-}
    
    2
    +module T28014b where
    
    3
    +
    
    4
    +pattern F :: a
    
    5
    +pattern F <- (const False -> True)
    
    6
    +{-# COMPLETE F #-}
    
    7
    +
    
    8
    +data G a where
    
    9
    +  G1' :: G Int
    
    10
    +  G2' :: G Bool
    
    11
    +
    
    12
    +data E a where
    
    13
    +  E1 :: E Bool
    
    14
    +
    
    15
    +-- | By the COMPLETE pragma, the first clause covers everything.
    
    16
    +w :: E a -> G a -> Int
    
    17
    +w F _   = 1
    
    18
    +w _ G1' = 2
    
    19
    +w _ G2' = 3

  • testsuite/tests/pmcheck/should_compile/T28014b.stderr
    1
    +T28014b.hs:18:1: warning: [GHC-53633] [-Woverlapping-patterns (in -Wdefault)]
    
    2
    +    Pattern match is redundant
    
    3
    +    In an equation for ‘w’: w _ G1' = ...
    
    4
    +
    
    5
    +T28014b.hs:19:1: warning: [GHC-53633] [-Woverlapping-patterns (in -Wdefault)]
    
    6
    +    Pattern match is redundant
    
    7
    +    In an equation for ‘w’: w _ G2' = ...
    
    8
    +

  • testsuite/tests/pmcheck/should_compile/all.T
    ... ... @@ -56,7 +56,7 @@ test('T17219', expect_broken(17219), compile, [overlapping_incomplete])
    56 56
     test('T17234', normal, compile, [overlapping_incomplete])
    
    57 57
     test('T17248', normal, compile, [overlapping_incomplete])
    
    58 58
     test('T17340', normal, compile, ['-Wredundant-bang-patterns'])
    
    59
    -test('T17357', expect_broken(17357), compile, [overlapping_incomplete])
    
    59
    +test('T17357', normal, compile, [overlapping_incomplete])
    
    60 60
     test('T17376', normal, compile, [overlapping_incomplete])
    
    61 61
     test('T17378', normal, compile, [overlapping_incomplete])
    
    62 62
     test('T17465', normal, compile, [overlapping_incomplete])
    
    ... ... @@ -195,3 +195,5 @@ test('T27323b', normal, compile, ['-Wredundant-bang-patterns'])
    195 195
     test('T27360', normal, compile, [overlapping_incomplete + '-g3'])
    
    196 196
     test('T27892a', normal, compile, [overlapping_incomplete])
    
    197 197
     test('T28095', normal, compile, [overlapping_incomplete])
    
    198
    +test('T28014', normal, compile, [overlapping_incomplete + '-Wredundant-bang-patterns'])
    
    199
    +test('T28014b', normal, compile, [overlapping_incomplete])