Gratuitous -Wincomplete-record-updates warning in do-notation
Summary
{-# OPTIONS_GHC -Wincomplete-record-updates #-}
data Foo = A {a :: Int} | B deriving Show
foo = A 4
-- wibble is safe - no warning
wibble = do
case foo of
bar@A{} -> Just bar{a = 9}
_ -> fail ":("
-- using guards doesn't throw a warning
twomble | bar@A{} <- foo = Just bar{a = 9}
| otherwise = fail ":("
-- sworble has the same semantics as wibble and twomble - but we get a warning!
sworble = do
bar@A{} <- Just foo
Just bar{a = 9}
Output:
DoBug.hs:19:8: warning: [-Wincomplete-record-updates]
Pattern match(es) are non-exhaustive
In a record-update construct: Patterns of type `Foo' not matched: B
|
19 | Just bar{a = 9}
| ^^^^^^^^^^
Expected behavior
Don't warn
Environment
- GHC version used: 9.3.20220401