Skip to content

Record update in GHCi is confused by data family instances

:seti -XTypeFamilies -XDuplicateRecordFields
data family D a
data instance D Int  = MkD0 | MkDInt { x :: Int, y :: Bool }
data instance D Bool = MkDBool { x :: Int }
f r = r { y = True, x = 14 }
error:
    * Constructor `MkDInt' does not have field `x'
    * In the expression: r {y = True, x = 14}
      In an equation for `f': f r = r {y = True, x = 14}
  |
5 | f r = r { y = True, x = 14 }
  |       ^^^^^^^^^^^^^^^^^^^^^^

GHC can compile this program just fine, it's only in GHCi that we get this weird behaviour. I think this is due to data family instances not being correctly added to con_fields in GHC.Tc.Module.runTcInteractive. I will fix in !8686 (merged).

Edited by sheaf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information