GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2022-09-01T19:25:51Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/15542DuplicateRecordFields not honored within a data family?2022-09-01T19:25:51ZmichalrusDuplicateRecordFields not honored within a data family?I’m observing some weird behavior, which is probably closely related to issue #15149.
The following minimized code does not compile on 8.2.1, 8.2.2, but it does compile on 8.4.3.
However, in my original (non-free) codebase, this is rev...I’m observing some weird behavior, which is probably closely related to issue #15149.
The following minimized code does not compile on 8.2.1, 8.2.2, but it does compile on 8.4.3.
However, in my original (non-free) codebase, this is reversed: 8.2.2 compiles it just fine, and 8.4.3 fails with both errors per usage location at the same time:
```
src/.../Docs.hs:123:11: error:
• Constructor ‘X'Y’ does not have the required strict field(s): z
...
src/.../Docs.hs:123:11: error:
• Constructor ‘X'Y’ does not have field ‘z’
```
I noticed, after updating the codebase’s compiler to 8.4.3.
If the `z` field is renamed and unique, it compiles correctly.
How can I go about debugging/minimizing this?
This is the minimized code that works the other way round (OK on 8.4.3, fails on 8.2.2):
```hs
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE StrictData #-}
module Main where
data AB = A | B
class SomeClass (ab :: AB) where
data SomeData ab
instance SomeClass 'A where
data SomeData 'A = SomeData'A{someField :: Int} deriving Show
instance SomeClass 'B where
data SomeData 'B = SomeData'B{someField :: Int}
main :: IO ()
main = print SomeData'A{someField = 5}
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.4.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"DuplicateRecordFields not honored within a data family?","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I’m observing some weird behavior, which is probably closely related to issue #15149.\r\n\r\nThe following minimized code does not compile on 8.2.1, 8.2.2, but it does compile on 8.4.3.\r\n\r\nHowever, in my original (non-free) codebase, this is reversed: 8.2.2 compiles it just fine, and 8.4.3 fails with both errors per usage location at the same time:\r\n\r\n{{{\r\nsrc/.../Docs.hs:123:11: error:\r\n • Constructor ‘X'Y’ does not have the required strict field(s): z\r\n\r\n...\r\n\r\nsrc/.../Docs.hs:123:11: error:\r\n • Constructor ‘X'Y’ does not have field ‘z’\r\n}}}\r\n\r\nI noticed, after updating the codebase’s compiler to 8.4.3.\r\n\r\nIf the `z` field is renamed and unique, it compiles correctly.\r\n\r\nHow can I go about debugging/minimizing this?\r\n\r\nThis is the minimized code that works the other way round (OK on 8.4.3, fails on 8.2.2):\r\n\r\n{{{#!hs\r\n{-# LANGUAGE DuplicateRecordFields #-}\r\n{-# LANGUAGE KindSignatures #-}\r\n{-# LANGUAGE DataKinds #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE StrictData #-}\r\n\r\nmodule Main where\r\n\r\ndata AB = A | B\r\n\r\nclass SomeClass (ab :: AB) where\r\n data SomeData ab\r\n\r\ninstance SomeClass 'A where\r\n data SomeData 'A = SomeData'A{someField :: Int} deriving Show\r\n\r\ninstance SomeClass 'B where\r\n data SomeData 'B = SomeData'B{someField :: Int}\r\n\r\nmain :: IO ()\r\nmain = print SomeData'A{someField = 5}\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/15149Identical distinct type family fields miscompiled2020-08-21T21:31:18ZNeil MitchellIdentical distinct type family fields miscompiledGiven 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
-- AnDoub...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).
<details><summary>Trac metadata</summary>
| 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 | |
</details>
<!-- {"blocked_by":[],"summary":"Identical distinct type family fields miscompiled","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["ndmitchell@gmail.com"],"type":"Bug","description":"Given the code:\r\n\r\n{{{#!hs\r\n-- An.hs\r\n{-# LANGUAGE TypeFamilies #-}\r\nmodule An where\r\ndata family An c :: *\r\n\r\n-- AnInt.hs\r\n{-# LANGUAGE TypeFamilies #-}\r\nmodule AnInt where\r\nimport An\r\ndata instance An Int = AnInt {an :: Int} deriving Show\r\n\r\n-- AnDouble.hs\r\n{-# LANGUAGE TypeFamilies #-}\r\nmodule AnDouble where\r\nimport An\r\ndata instance An Double = AnDouble {an :: Double} deriving Show\r\n\r\n-- Main.hs\r\n{-# LANGUAGE DisambiguateRecordFields #-}\r\nmodule Main where\r\nimport AnInt\r\nimport AnDouble\r\nmain = print (AnDouble{an=1}, AnInt{an=1})\r\n}}}\r\n\r\nI would expect this code to work. In reality it fails at runtime with GHC 8.2.2:\r\n\r\n{{{\r\nMain.hs:4:15-28: warning: [-Wmissing-fields]\r\n * Fields of `AnDouble' not initialised: an\r\n * In the expression: AnDouble {an = 1}\r\n In the first argument of `print', namely\r\n `(AnDouble {an = 1}, AnInt {an = 1})'\r\n In the expression: print (AnDouble {an = 1}, AnInt {an = 1})\r\n |\r\n6 | main = print (AnDouble{an=1}, AnInt{an=1})\r\n | ^^^^^^^^^^^^^^\r\n\r\n*** Exception: Main.hs:4:15-28: Missing field in record construction an\r\n}}}\r\n\r\nAnd fails at compile time in GHC 8.4.2:\r\n\r\n{{{\r\nMain.hs:4:31-41: error:\r\n * Constructor `AnInt' does not have field `an'\r\n * In the expression: AnInt {an = 1}\r\n In the first argument of `print', namely\r\n `(AnDouble {an = 1}, AnInt {an = 1})'\r\n In the expression: print (AnDouble {an = 1}, AnInt {an = 1})\r\n |\r\n6 | main = print (AnDouble{an=1}, AnInt{an=1})\r\n | ^^^^^^^^^^^\r\n}}}\r\n\r\nThis 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).","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1Adam GundryAdam Gundryhttps://gitlab.haskell.org/ghc/ghc/-/issues/14953Panic when exporting duplicate record fields from separate modules2019-07-07T18:14:54ZlyxiaPanic when exporting duplicate record fields from separate modules`A.hs`
```hs
{-# LANGUAGE DuplicateRecordFields #-}
module A where
data R = R {unR :: Int}
```
---
`B.hs`
```hs
{-# LANGUAGE DuplicateRecordFields #-}
module B where
data R = R {unR :: Int}
```
---
`C.hs`
```hs
{-# LANGUAGE Duplic...`A.hs`
```hs
{-# LANGUAGE DuplicateRecordFields #-}
module A where
data R = R {unR :: Int}
```
---
`B.hs`
```hs
{-# LANGUAGE DuplicateRecordFields #-}
module B where
data R = R {unR :: Int}
```
---
`C.hs`
```hs
{-# LANGUAGE DuplicateRecordFields #-}
module C (module A, module B) where
import A
import B
```
---
Output of `ghc C.hs`:
```
C.hs:3:21: error:ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.5.20180224 for x86_64-unknown-linux):
exportClashErr
$sel:unR:R
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcRnExports.hs:740:22 in ghc:TcRnExports
```8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/14487Can't Hide Field When DuplicateRecordFields Is Enabled2019-07-07T18:16:50Ziansullivan88Can't Hide Field When DuplicateRecordFields Is EnabledA.hs fails to compile when DuplicateRecordFields is enabled in B.hs.
A.hs
```hs
module A where
import B hiding (duplicateName)
test = X duplicateName
duplicateName = 5
```
B.hs
```hs
{-# LANGUAGE DuplicateRecordFields #...A.hs fails to compile when DuplicateRecordFields is enabled in B.hs.
A.hs
```hs
module A where
import B hiding (duplicateName)
test = X duplicateName
duplicateName = 5
```
B.hs
```hs
{-# LANGUAGE DuplicateRecordFields #-}
module B where
data X = X {
duplicateName :: Int
}
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | lowest |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Can't Hide Field When DuplicateRecordFields Is Enabled","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":["DuplicateRecordFields"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"A.hs fails to compile when DuplicateRecordFields is enabled in B.hs.\r\n\r\nA.hs\r\n{{{#!hs\r\nmodule A where\r\n\r\nimport B hiding (duplicateName)\r\n\r\ntest = X duplicateName\r\n\r\nduplicateName = 5\r\n\r\n}}}\r\n\r\nB.hs\r\n{{{#!hs\r\n{-# LANGUAGE DuplicateRecordFields #-}\r\n\r\nmodule B where\r\n\r\ndata X = X {\r\n duplicateName :: Int\r\n}\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1