Opened 12 months ago

Last modified 6 months ago

#15713 new bug

Bogus -Woverlapping-patterns warning with OverloadedStrings

Reported by: quasicomputational Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.6.1
Keywords: PatternMatchWarnings Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

$ cat Test.hs
{-# LANGUAGE OverloadedStrings, LambdaCase #-}
import Data.String

data Expr = App Expr Expr | Var String
  deriving (Eq)

instance IsString Expr where
  fromString = Var . fromString

go = \case
  App ( App ( App "refWithFile" identM ) filenameM) exceptionMayM -> Just 2
  App ( App "and" a ) b -> Just 3
  App ( App "or" a ) b -> Just 4
  _ -> Nothing

go' = \case
  App ( App ( App "refWithFile" identM ) filenameM) exceptionMayM -> Just 2
  App ( App "and" a ) b -> Just 3
  _ -> Nothing

go'' = \case
  App ( App ( App (Var "refWithFile") identM ) filenameM) exceptionMayM -> Just 2
  App ( App (Var "and") a ) b -> Just 3
  App ( App (Var "or") a ) b -> Just 4
  _ -> Nothing

main = do
  let expr = App (App "or" "a") "b"
  print (go expr)
  print (go' expr)

$ runghc-8.4.3 Test.hs

Test.hs:13:3: warning: [-Woverlapping-patterns]
    Pattern match is redundant
    In a case alternative: App (App "or" a) b -> ...
   |
13 |   App ( App "or" a ) b -> Just 4
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Just 4
Nothing
$ runghc-8.6.1 Test.hs

Test.hs:13:3: warning: [-Woverlapping-patterns]
    Pattern match is redundant
    In a case alternative: App (App "or" a) b -> ...
   |
13 |   App ( App "or" a ) b -> Just 4
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Just 4
Nothing

The pattern match checker complains about the "or" case of go being redundant, but, when it is removed (as it is in go') the output is different. go'' demonstrates that OverloadedStrings is relevant, as that is *not* generating a warning. Removing either of the other two cases of go also suppresses the warning: all three are necessary.

As seen in the transcript, this is happening on both 8.4.3 and 8.6.1.

Change History (2)

comment:1 Changed 12 months ago by RyanGlScott

Keywords: PatternMatchWarnings added

comment:2 Changed 6 months ago by Marge Bot <ben+marge-bot@…>

In 4626cf2/ghc:

Fix Uncovered set of literal patterns

Issues #16289 and #15713 are proof that the pattern match checker did
an unsound job of estimating the value set abstraction corresponding to
the uncovered set.

The reason is that the fix from #11303 introducing `NLit` was
incomplete: The `LitCon` case desugared to `Var` rather than `LitVar`,
which would have done the necessary case splitting analogous to the
`ConVar` case.

This patch rectifies that by introducing the fresh unification variable
in `LitCon` in value abstraction position rather than pattern postition,
recording a constraint equating it to the constructor expression rather
than the literal. Fixes #16289 and #15713.
Note: See TracTickets for help on using tickets.