Skip to content

GHC 9.2 warns about code that 8.10 accepts

Summary

The code in the reproducer issues a warning in ghc-9.2 but not in ghc-8.10.

Related to #15656 (closed)

Steps to reproduce

{-# OPTIONS_GHC -Wno-unused-top-binds #-}

-- Build with `ghc -Wall -Werror reproducer.hs -o reproducer`

-- Data structures cargo culted from `aeson` library and then minimised.

data SumEncoding
  = TaggedObject { tagFieldName :: String, contentsFieldName :: String }
  | UntaggedValue

data Options = Options
    { sumEncoding :: SumEncoding
    }

defaultOptions :: Options
defaultOptions =
  Options { sumEncoding = defaultTaggedObject }

defaultTaggedObject :: SumEncoding
defaultTaggedObject =
  TaggedObject { tagFieldName = "tag", contentsFieldName = "contents" }

encodingOptions :: Options
encodingOptions = defaultOptions
  { sumEncoding =
      defaultTaggedObject
       { tagFieldName = "kind"
       }
  }

main :: IO ()
main = putStrLn "Hello, World!"

Builds fine with ghc-8.10.7 and with ghc-9.2.4 warns:

reproducer.hs:29:7: error: [-Wincomplete-record-updates, -Werror=incomplete-record-updates]
    Pattern match(es) are non-exhaustive
    In a record-update construct:
        Patterns of type ‘SumEncoding’ not matched: UntaggedValue
   |
29 |       defaultTaggedObject
   |       ^^^^^^^^^^^^^^^^^^^...

Expected behavior

Do not expect a warning from this code.

Environment

  • GHC version used: 8.10.7 and 9.2.4
Edited by sheaf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information