GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2023-07-19T13:52:57Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/23698RecordWildCards implies NamedFieldPuns as of GHC 9.22023-07-19T13:52:57ZMarioRecordWildCards implies NamedFieldPuns as of GHC 9.2## Summary
Intentionally or not, the `RecordWildCards` extension appears to imply `NamedFieldPuns` since GHC 9.2. This is not documented. I'm filing the issue as a bug, but it may just be a documentation oversight if the change was inte...## Summary
Intentionally or not, the `RecordWildCards` extension appears to imply `NamedFieldPuns` since GHC 9.2. This is not documented. I'm filing the issue as a bug, but it may just be a documentation oversight if the change was intentional.
## Steps to reproduce
```
$ cat RecordWildCards.hs
{-# LANGUAGE RecordWildCards #-}
data E = MkE {a :: Int, b :: [Int]}
f MkE{a, b} = f MkE{a, b}
main = putStrLn "Compiles."
$ runghc-9.2.5 RecordWildCards.hs
Compiles.
$ runghc-9.0.2 RecordWildCards.hs
RecordWildCards.hs:5:3: error:
Illegal use of punning for field ‘a’
Use NamedFieldPuns to permit this
|
5 | f MkE{a, b} = f MkE{a, b}
| ^^^^^^^^^
...
```
## Expected behavior
Same as GHC 9.0.2
## Environment
* GHC version used: 9.2.5
Optional:
* Operating System: Fedora
* System Architecture: x86_64https://gitlab.haskell.org/ghc/ghc/-/issues/22161Allow record wildcards for empty records2023-02-22T02:08:01ZGeorgi LyubenovAllow record wildcards for empty recordsCreating this as a tracking ticket for the implementation of https://github.com/ghc-proposals/ghc-proposals/pull/496, which is already accepted.
The idea is to allow
```haskell
data Foo = Foo { }
f (Foo {..}) = 1
x = Foo {..}
```
for...Creating this as a tracking ticket for the implementation of https://github.com/ghc-proposals/ghc-proposals/pull/496, which is already accepted.
The idea is to allow
```haskell
data Foo = Foo { }
f (Foo {..}) = 1
x = Foo {..}
```
for consistency with non-empty records. Other than aesthetic reasons, this is also practically useful for code generation - you can treat record matching with a wildcard the same way, regardless of how many fields the record being matched has.
Notably,
```haskell
data Foo = Foo
f (Foo {..}) = 42
```
is also allowed, despite the inconsistency it causes with regards to having to now differentiate between `n = 0` and `n > 0`, where `n` is the number of arguments the constructor `Foo` has.
This seems to have been briefly discussed in the linked proposal.
To summarise, the new behaviour should be:
Only reject a wildcard when the constructor it's attached to is not a record and has at least one argument/field.
I'll be implementing this.
Implementation notes:
The error that's currently produced is `GHC.Tc.Errors.Types.TcRnIllegalWildcardsInConstructor`.
The comment attached to it should be amended to reflect the new reality.
It's produced only in `GHC.Rename.Pat.rnHsRecFields.rn_dotdot`. The check there needs to be amended to also find out if the constructor has non-record arguments.Georgi LyubenovGeorgi Lyubenovhttps://gitlab.haskell.org/ghc/ghc/-/issues/9975RecordWildcards and PatternSynonyms cause impossible bug2021-05-17T16:05:16ZgamegoblinRecordWildcards and PatternSynonyms cause impossible bugWhen using RecordWildcards with PatternSynonyms, I have found a way to cause this bug:
```
$ /usr/local/bin/ghc-7.10.0.20141222 test.hs
[1 of 1] Compiling Main ( test.hs, test.o )
ghc: panic! (the 'impossible' happened)
(...When using RecordWildcards with PatternSynonyms, I have found a way to cause this bug:
```
$ /usr/local/bin/ghc-7.10.0.20141222 test.hs
[1 of 1] Compiling Main ( test.hs, test.o )
ghc: panic! (the 'impossible' happened)
(GHC version 7.10.0.20141222 for x86_64-apple-darwin):
find_tycon
Test
[Test defined at test.hs:6:9,
Test parent:Test defined at test.hs:4:13]
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
Here is the full code that causes it:
```hs
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE PatternSynonyms #-}
data Test = Test { x :: Int }
pattern Test wat = Test { x = wat }
```
If you remove `RecordWildCards`, the bug does not happen.7.10.1https://gitlab.haskell.org/ghc/ghc/-/issues/9815Runtime error with RecordWildCards and a non-record constructor2019-07-07T18:38:57Ztakano-akioRuntime error with RecordWildCards and a non-record constructorThe following program is accepted with no warning, and crashes at runtime with an error:
```hs
{-# LANGUAGE RecordWildCards #-}
newtype N = N Int deriving (Show)
main = print N{..}
```
```
% runghc wildcards.hs
wildcards.hs: wildcar...The following program is accepted with no warning, and crashes at runtime with an error:
```hs
{-# LANGUAGE RecordWildCards #-}
newtype N = N Int deriving (Show)
main = print N{..}
```
```
% runghc wildcards.hs
wildcards.hs: wildcards.hs:4:14-18: Missing field in record construction
```
I find this behavior surprising. Would it be better to either disallow it or have `-fwarn-missing-fields` warn it?
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 7.8.3 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Runtime error with RecordWildCards and a non-record constructor","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.8.3","keywords":["RecordWildCards,","warning"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"The following program is accepted with no warning, and crashes at runtime with an error:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RecordWildCards #-}\r\nnewtype N = N Int deriving (Show)\r\n\r\nmain = print N{..}\r\n}}}\r\n\r\n{{{\r\n% runghc wildcards.hs \r\nwildcards.hs: wildcards.hs:4:14-18: Missing field in record construction\r\n}}}\r\n\r\nI find this behavior surprising. Would it be better to either disallow it or have `-fwarn-missing-fields` warn it?","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/10520RecordWildCards causes “is not a (visible) field of constructor” in ghci2019-07-07T18:35:35Zion1RecordWildCards causes “is not a (visible) field of constructor” in ghci```
% ghc -ignore-dot-ghci -e 'data Foo = Bar { baz :: Integer } deriving Show' -e 'Bar 42' -e '(Bar 42){ baz = 43 }' -e 'Bar { baz = 42 }'
Bar {baz = 42}
Bar {baz = 43}
Bar {baz = 42}
```
```
% ghc -ignore-dot-ghci -XRecordWildCards -e...```
% ghc -ignore-dot-ghci -e 'data Foo = Bar { baz :: Integer } deriving Show' -e 'Bar 42' -e '(Bar 42){ baz = 43 }' -e 'Bar { baz = 42 }'
Bar {baz = 42}
Bar {baz = 43}
Bar {baz = 42}
```
```
% ghc -ignore-dot-ghci -XRecordWildCards -e 'data Foo = Bar { baz :: Integer } deriving Show' -e 'Bar 42' -e '(Bar 42){ baz = 43 }' -e 'Bar { baz = 42 }'
Bar {baz = 42}
Bar {baz = 43}
<interactive>:1:7:
‘baz’ is not a (visible) field of constructor ‘Bar’
```
```
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.1
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | GHCi |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | hvr |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"RecordWildCards causes “is not a (visible) field of constructor” in ghci","status":"New","operating_system":"","component":"GHCi","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.1","keywords":["RecordWildCards"],"differentials":[],"test_case":"","architecture":"","cc":["hvr"],"type":"Bug","description":"{{{\r\n% ghc -ignore-dot-ghci -e 'data Foo = Bar { baz :: Integer } deriving Show' -e 'Bar 42' -e '(Bar 42){ baz = 43 }' -e 'Bar { baz = 42 }'\r\nBar {baz = 42}\r\nBar {baz = 43}\r\nBar {baz = 42}\r\n}}}\r\n\r\n{{{\r\n% ghc -ignore-dot-ghci -XRecordWildCards -e 'data Foo = Bar { baz :: Integer } deriving Show' -e 'Bar 42' -e '(Bar 42){ baz = 43 }' -e 'Bar { baz = 42 }'\r\nBar {baz = 42}\r\nBar {baz = 43}\r\n\r\n<interactive>:1:7:\r\n ‘baz’ is not a (visible) field of constructor ‘Bar’\r\n}}}\r\n\r\n{{{\r\n% ghc --version\r\nThe Glorious Glasgow Haskell Compilation System, version 7.10.1\r\n}}}\r\n","type_of_failure":"OtherFailure","blocking":[]} -->8.0.1https://gitlab.haskell.org/ghc/ghc/-/issues/14549RecordWildCards doesn't work properly in repl2019-07-07T18:16:33ZakegaljRecordWildCards doesn't work properly in repl```hs
Prelude> :set -XRecordWildCards
Prelude> data Test = Test { t1 :: Int, t2 :: Int } deriving Show
Prelude> t1 = 2
Prelude> Test { t2 = 2, ..}
<interactive>:15:1: warning: [-Wmissing-fields]
• Fields of 'Test' not initialised: t...```hs
Prelude> :set -XRecordWildCards
Prelude> data Test = Test { t1 :: Int, t2 :: Int } deriving Show
Prelude> t1 = 2
Prelude> Test { t2 = 2, ..}
<interactive>:15:1: warning: [-Wmissing-fields]
• Fields of 'Test' not initialised: t1
• In the expression: Test {t2 = 2, ..}
In an equation for 'it': it = Test {t2 = 2, ..}
<interactive>:15:1: warning: [-Wmissing-fields]
• Fields of 'Test' not initialised: t1
• In the expression: Test {t2 = 2, ..}
In an equation for 'it': it = Test {t2 = 2, ..}
Test {t1 = *** Exception: <interactive>:15:1-18: Missing field in record construction t1
```
I would expect above to return `Test {t1 = 2, t2 = 2}` instead of throwing an error.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.2.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | lowest |
| Resolution | Unresolved |
| Component | GHCi |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"RecordWildCards doesn't work properly in repl","status":"New","operating_system":"","component":"GHCi","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.1","keywords":["recordwildcards","repl,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{#!hs\r\nPrelude> :set -XRecordWildCards\r\nPrelude> data Test = Test { t1 :: Int, t2 :: Int } deriving Show\r\nPrelude> t1 = 2\r\nPrelude> Test { t2 = 2, ..}\r\n\r\n<interactive>:15:1: warning: [-Wmissing-fields]\r\n • Fields of 'Test' not initialised: t1\r\n • In the expression: Test {t2 = 2, ..}\r\n In an equation for 'it': it = Test {t2 = 2, ..}\r\n\r\n<interactive>:15:1: warning: [-Wmissing-fields]\r\n • Fields of 'Test' not initialised: t1\r\n • In the expression: Test {t2 = 2, ..}\r\n In an equation for 'it': it = Test {t2 = 2, ..}\r\nTest {t1 = *** Exception: <interactive>:15:1-18: Missing field in record construction t1\r\n}}}\r\n\r\n\r\nI would expect above to return `Test {t1 = 2, t2 = 2}` instead of throwing an error.","type_of_failure":"OtherFailure","blocking":[]} -->