
#15149: Identical distinct type family fields miscompiled -------------------------------------+------------------------------------- Reporter: NeilMitchell | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Given the code: {{{#!hs -- An.hs {-# LANGUAGE TypeFamilies #-} module An where data family An c :: * -- AnInt.hs {-# LANGUAGE TypeFamilies #-} module AnInt where import An data instance An Int = AnInt {an :: Int} deriving Show -- AnDouble.hs {-# LANGUAGE TypeFamilies #-} module AnDouble where import An data instance An Double = AnDouble {an :: Double} deriving Show -- Main.hs {-# LANGUAGE DisambiguateRecordFields #-} module Main where import AnInt import AnDouble main = print (AnDouble{an=1}, AnInt{an=1}) }}} I would expect this code to work. In reality it fails at runtime with GHC 8.2.2: {{{ Main.hs:4:15-28: warning: [-Wmissing-fields] * Fields of `AnDouble' not initialised: an * In the expression: AnDouble {an = 1} In the first argument of `print', namely `(AnDouble {an = 1}, AnInt {an = 1})' In the expression: print (AnDouble {an = 1}, AnInt {an = 1}) | 6 | main = print (AnDouble{an=1}, AnInt{an=1}) | ^^^^^^^^^^^^^^ *** Exception: Main.hs:4:15-28: Missing field in record construction an }}} And fails at compile time in GHC 8.4.2: {{{ Main.hs:4:31-41: error: * Constructor `AnInt' does not have field `an' * In the expression: AnInt {an = 1} In the first argument of `print', namely `(AnDouble {an = 1}, AnInt {an = 1})' In the expression: print (AnDouble {an = 1}, AnInt {an = 1}) | 6 | main = print (AnDouble{an=1}, AnInt{an=1}) | ^^^^^^^^^^^ }}} This code was extracted from a real example, where this bug is pretty fatal, as I haven't been able to find any workarounds (without just avoiding clashing record fields). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15149 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler