Identical distinct type family fields miscompiled
Given the code:
-- 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).
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.4.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | ndmitchell@gmail.com |
| Operating system | |
| Architecture |