GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2022-06-11T11:27:34Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/11103DuplicateRecordFields + TemplateHaskell2022-06-11T11:27:34ZAdam GundryDuplicateRecordFields + TemplateHaskellThe [DuplicateRecordFields](records/overloaded-record-fields/duplicate-record-fields) extension works by mangling the Names of field selector functions, and treating fields specially in the renamer. Thus if you define
```
data T = MkT {...The [DuplicateRecordFields](records/overloaded-record-fields/duplicate-record-fields) extension works by mangling the Names of field selector functions, and treating fields specially in the renamer. Thus if you define
```
data T = MkT { foo :: Int }
```
then GHC will actually generate a selector called `$sel:foo:MkT`, but will resolve `foo` to refer to this selector.
In general we want this name-mangling to be internal only, but at the moment it is visible when using Template Haskell, because the TH AST doesn't have a way to represent the distinction between the selector name and the field label. For example, if you reify `''T` above and then pretty-print it you will currently get
```
data T = MkT { $sel:foo:MkT :: Int }
```
which is obviously bad.
I'm not sure how best to address this. We could represent the name as `mkNameG_v pkg mod "foo"`, which will look okay when inspected, but if it is subsequently reified it might be ambiguous. Should we add a new `NameFlavour`?
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---------------- |
| Version | 7.11 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Template Haskell |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"DuplicateRecordFields + TemplateHaskell","status":"New","operating_system":"","component":"Template Haskell","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.11","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The [wiki:Records/OverloadedRecordFields/DuplicateRecordFields DuplicateRecordFields] extension works by mangling the Names of field selector functions, and treating fields specially in the renamer. Thus if you define\r\n{{{\r\ndata T = MkT { foo :: Int }\r\n}}}\r\nthen GHC will actually generate a selector called `$sel:foo:MkT`, but will resolve `foo` to refer to this selector.\r\n\r\nIn general we want this name-mangling to be internal only, but at the moment it is visible when using Template Haskell, because the TH AST doesn't have a way to represent the distinction between the selector name and the field label. For example, if you reify `''T` above and then pretty-print it you will currently get\r\n{{{\r\ndata T = MkT { $sel:foo:MkT :: Int }\r\n}}}\r\nwhich is obviously bad.\r\n\r\nI'm not sure how best to address this. We could represent the name as `mkNameG_v pkg mod \"foo\"`, which will look okay when inspected, but if it is subsequently reified it might be ambiguous. Should we add a new `NameFlavour`?","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Adam GundryAdam Gundryhttps://gitlab.haskell.org/ghc/ghc/-/issues/10306Calling reify on Any or built-in type families causes panic2019-07-07T18:36:39ZAdam GundryCalling reify on Any or built-in type families causes panicBoth `reify ''Any` and `reify ''(+)` (where `(+)` is the built-in operation on type-level naturals) result in a panic `TcSplice.reifyFamFlavour: not a type family`. I came across this while working on #9840 and have a fix as part of [D84...Both `reify ''Any` and `reify ''(+)` (where `(+)` is the built-in operation on type-level naturals) result in a panic `TcSplice.reifyFamFlavour: not a type family`. I came across this while working on #9840 and have a fix as part of [D841](https://phabricator.haskell.org/D841).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.10.1 |
| 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":"Calling reify on Any or built-in type families causes panic","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"adamgundry"},"version":"7.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Both `reify ''Any` and `reify ''(+)` (where `(+)` is the built-in operation on type-level naturals) result in a panic `TcSplice.reifyFamFlavour: not a type family`. I came across this while working on #9840 and have a fix as part of Phab:D841.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Adam GundryAdam Gundryhttps://gitlab.haskell.org/ghc/ghc/-/issues/11173Infix declarations for record fields with DuplicateRecordFields are broken2019-07-07T18:31:38ZkanetwInfix declarations for record fields with DuplicateRecordFields are brokenThe following program compiles fine
```hs
module Good where
newtype A = A { foo :: Int }
infixl 5 `foo`
```
but this one doesn't
```hs
{-# LANGUAGE DuplicateRecordFields #-}
module Bad where
newtype A = A { foo :: Int }
infixl 5 `foo`...The following program compiles fine
```hs
module Good where
newtype A = A { foo :: Int }
infixl 5 `foo`
```
but this one doesn't
```hs
{-# LANGUAGE DuplicateRecordFields #-}
module Bad where
newtype A = A { foo :: Int }
infixl 5 `foo`
```
giving an error
```
The fixity signature for ‘foo’ lacks an accompanying binding
(The fixity signature must be given where ‘foo’ is declared)
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.11 |
| 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":"Infix declarations for record fields with DuplicateRecordFields are broken","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.11","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program compiles fine\r\n{{{#!hs\r\nmodule Good where\r\nnewtype A = A { foo :: Int }\r\ninfixl 5 `foo`\r\n}}}\r\n\r\nbut this one doesn't\r\n\r\n{{{#!hs\r\n{-# LANGUAGE DuplicateRecordFields #-}\r\nmodule Bad where\r\nnewtype A = A { foo :: Int }\r\ninfixl 5 `foo`\r\n}}}\r\ngiving an error\r\n{{{\r\nThe fixity signature for ‘foo’ lacks an accompanying binding\r\n (The fixity signature must be given where ‘foo’ is declared)\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Adam GundryAdam Gundryhttps://gitlab.haskell.org/ghc/ghc/-/issues/11283PatternSynonms and DisambiguateRecordFields causes panic2019-07-07T18:31:07ZAdam GundryPatternSynonms and DisambiguateRecordFields causes panicThe following module causes a panic in HEAD:
```hs
{-# LANGUAGE PatternSynonyms, DisambiguateRecordFields #-}
data P a = MkP a
pattern S{x} = MkP x
e = S{x = 3}
```
```
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 7.11...The following module causes a panic in HEAD:
```hs
{-# LANGUAGE PatternSynonyms, DisambiguateRecordFields #-}
data P a = MkP a
pattern S{x} = MkP x
e = S{x = 3}
```
```
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 7.11.20151223 for x86_64-unknown-linux):
find_tycon
S
[S pattern synonym defined at PatSynBug.hs:3:1]
```
This is essentially the same bug as #9975; for some reason it became slightly harder to tickle. Fix incoming.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.11 |
| 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":"PatternSynonms and DisambiguateRecordFields causes panic","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"adamgundry"},"version":"7.11","keywords":["PatternSynonyms"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following module causes a panic in HEAD:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE PatternSynonyms, DisambiguateRecordFields #-}\r\ndata P a = MkP a\r\npattern S{x} = MkP x\r\ne = S{x = 3}\r\n}}}\r\n\r\n{{{\r\nghc-stage2: panic! (the 'impossible' happened)\r\n (GHC version 7.11.20151223 for x86_64-unknown-linux):\r\n\tfind_tycon\r\n S\r\n [S pattern synonym defined at PatSynBug.hs:3:1]\r\n}}}\r\n\r\nThis is essentially the same bug as #9975; for some reason it became slightly harder to tickle. Fix incoming.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Adam GundryAdam Gundryhttps://gitlab.haskell.org/ghc/ghc/-/issues/11328Auto complete in ghci shows $sel:function:Type for DuplicateRecordFields fields2019-07-07T18:30:54Zkolmodin@dtek.chalmers.seAuto complete in ghci shows $sel:function:Type for DuplicateRecordFields fieldsGiven a haskell file;
```hs
{-# LANGUAGE DuplicateRecordFields #-}
-- t.hs
data A = A { name :: String }
data B = B { name :: String }
```
and in GHCi;
```
ghci t.hs
GHCi, version 8.1.20151231: http://www.haskell.org/ghc/ :? for hel...Given a haskell file;
```hs
{-# LANGUAGE DuplicateRecordFields #-}
-- t.hs
data A = A { name :: String }
data B = B { name :: String }
```
and in GHCi;
```
ghci t.hs
GHCi, version 8.1.20151231: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( tnum.hs, interpreted )
Ok, modules loaded: Main.
*Main> <TAB> <TAB>
...
$sel:name:A
$sel:name:B
...
```
The records show up as `$sel:function:Type`, a function which you cannot refer to by name.
Even if you enable `OverloadedLabels`, the `#labels` don't show up in the auto completion.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1-rc1 |
| 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":"Auto complete in ghci shows $sel:function:Type for DuplicateRecordFields fields","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"\r\nGiven a haskell file;\r\n\r\n{{{#!hs\r\n{-# LANGUAGE DuplicateRecordFields #-}\r\n-- t.hs\r\n\r\ndata A = A { name :: String }\r\ndata B = B { name :: String }\r\n}}}\r\n\r\nand in GHCi;\r\n\r\n{{{\r\nghci t.hs\r\nGHCi, version 8.1.20151231: http://www.haskell.org/ghc/ :? for help\r\n[1 of 1] Compiling Main ( tnum.hs, interpreted )\r\nOk, modules loaded: Main.\r\n*Main> <TAB> <TAB>\r\n...\r\n$sel:name:A\r\n$sel:name:B\r\n...\r\n\r\n}}}\r\n\r\nThe records show up as `$sel:function:Type`, a function which you cannot refer to by name.\r\n\r\nEven if you enable `OverloadedLabels`, the `#labels` don't show up in the auto completion.","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Adam GundryAdam Gundryhttps://gitlab.haskell.org/ghc/ghc/-/issues/11662Regression using NamedFieldPuns with qualified field names2019-07-07T18:29:13ZhesselinkRegression using NamedFieldPuns with qualified field namesI found a regression where code using the NamedFieldPuns extension and qualified field names doesn't compile with GHC 8 rc2, where it did with GHC 7.10.
Minimal reproduction:
```hs
module Rec where
data Rec = Rec { f :: Integer }
---...I found a regression where code using the NamedFieldPuns extension and qualified field names doesn't compile with GHC 8 rc2, where it did with GHC 7.10.
Minimal reproduction:
```hs
module Rec where
data Rec = Rec { f :: Integer }
--------------------
{-# LANGUAGE NamedFieldPuns #-}
module Main where
import Rec (Rec (Rec))
import qualified Rec
g :: Rec -> Integer
g (Rec { Rec.f }) = f
```
On GHC 8 this fails with:
```
Main.hs:6:10: error: Qualified name in binding position: Rec.f
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1-rc2 |
| 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":"Regression using NamedFieldPuns with qualified field names","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1-rc2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I found a regression where code using the NamedFieldPuns extension and qualified field names doesn't compile with GHC 8 rc2, where it did with GHC 7.10.\r\n\r\nMinimal reproduction:\r\n\r\n{{{#!hs\r\nmodule Rec where\r\n\r\ndata Rec = Rec { f :: Integer }\r\n\r\n--------------------\r\n\r\n{-# LANGUAGE NamedFieldPuns #-}\r\nmodule Main where\r\n\r\nimport Rec (Rec (Rec))\r\nimport qualified Rec\r\n\r\ng :: Rec -> Integer\r\ng (Rec { Rec.f }) = f\r\n}}}\r\n\r\nOn GHC 8 this fails with:\r\n\r\n{{{\r\nMain.hs:6:10: error: Qualified name in binding position: Rec.f\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1Adam GundryAdam Gundry