GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2021-05-17T16:05:16Zhttps://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/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/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/23004Typed holes should take record wildcards into account2023-02-21T15:33:32ZJaro ReindersTyped holes should take record wildcards into account## Summary
When using record wildcards together with typed holes, you don't get very useful information.
This is especially painful if you are using record wildcards as a workaround for #12376 (as suggested in comment https://gitlab.ha...## Summary
When using record wildcards together with typed holes, you don't get very useful information.
This is especially painful if you are using record wildcards as a workaround for #12376 (as suggested in comment https://gitlab.haskell.org/ghc/ghc/-/issues/12376#note_125684). And also if you are using typed holes in combination with tools like [wingman](https://haskellwingman.dev/) which gives typed holes superpowers.
## Steps to reproduce
```haskell
{-# LANGUAGE RecordWildCards #-}
data Foo = Foo {foo :: Int}
test :: Foo
test = Foo {..}
where
foo = _
```
Gives the suggestion:
```
T.hs:8:11: error:
• Found hole: _ :: p
Where: ‘p’ is a rigid type variable bound by
the inferred type of foo :: p
at T.hs:8:5-11
• In an equation for ‘foo’: foo = _
In an equation for ‘test’:
test
= Foo {..}
where
foo = _
• Relevant bindings include
foo :: p (bound at T.hs:8:5)
test :: Foo (bound at T.hs:6:1)
|
8 | foo = _
| ^
```
## Expected behavior
GHC should say that the type of the hole must be `Int` because that is the type of the `foo` field. The typed holes should be consistent with the type error you get when you use a wrong type, e.g.:
```haskell
{-# LANGUAGE RecordWildCards #-}
data Foo = Foo {foo :: Int}
test :: Foo
test = Foo {..}
where
foo = ()
```
Gives the error:
```
T.hs:6:13: error:
• Couldn't match expected type ‘Int’ with actual type ‘()’
• In the ‘foo’ field of a record
In the expression: Foo {..}
In an equation for ‘test’:
test
= Foo {..}
where
foo = ()
|
6 | test = Foo {..}
| ^^
```
So GHC does know that `foo :: Int` should hold.
## Environment
* GHC version used: 9.2.4https://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/20193RecordWildCards undocumented behavior2021-08-16T08:33:20ZYuriy SyrovetskiyRecordWildCards undocumented behavior## Summary
https://downloads.haskell.org/ghc/latest/docs/html/users_guide/exts/record_wildcards.html
There are two behaviors of RecordWildCards (RWC) undocumented or documented unclearly.
### 1. Unclear qualified names
> For both pat...## Summary
https://downloads.haskell.org/ghc/latest/docs/html/users_guide/exts/record_wildcards.html
There are two behaviors of RecordWildCards (RWC) undocumented or documented unclearly.
### 1. Unclear qualified names
> For both pattern and expression wildcards, the “`..`” expands to the missing in-scope record fields...
>
> The record field `f` is in scope somehow (either qualified or unqualified).
>
> ```hs
> module M where
> data R = R { a,b,c :: Int }
> module X where
> import M( R(R,a,c) )
> f a b = R { .. }
> ```
>
> The `R{..}` expands to `R{a=a}`
There should be an example of qualified in-scope presence, which I find very useful
```hs
module M where
data R = R{a, b, c :: Int}
module X where
import M (R (R))
import M qualified
f a b = R{..}
```
The `R{..}` expands to `R{M.a = a, M.b = b}`, so you can use fields without messing with getters.
### 2. RWC interferes with NamedFieldPuns
With NamedFieldPuns (NFP) enabled and RWC disabled:
```hs
import M (R (R))
import M qualified
f foo = R{foo} -- use of NFP syntax, not RWC
```
```
error:
Not in scope: ‘foo’
Perhaps you want to add ‘foo’ to the import list in the import of
```
With RWC additionally enabled, the same code is compiled successfully!
So, RWC desugars NFP syntax `R{foo}` to `R{M.foo = foo}`, which must be documented.
## Proposed improvements or changes
I'm not sure about specific wording.
## Environment
* GHC version used: 8.10.4https://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/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":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/17834Support RecordWildCards in HPC2020-06-29T20:59:20ZBrandon ChinnSupport RecordWildCards in HPC## Summary
Data type records are marked as "never executed" when I use them only with RecordWildCards. The same could probably be said for NamedFieldPuns as well.
## Steps to reproduce
```haskell
{-# LANGUAGE RecordWildCards #-}
data...## Summary
Data type records are marked as "never executed" when I use them only with RecordWildCards. The same could probably be said for NamedFieldPuns as well.
## Steps to reproduce
```haskell
{-# LANGUAGE RecordWildCards #-}
data Foo = Foo
{ foo1 :: Int
, foo2 :: Int
}
showFoo :: Foo -> IO ()
showFoo Foo{..} = print (foo1, foo2)
main = showFoo (Foo 1 2)
```
Running the above with coverage shows `foo1` and `foo2` as uncovered.
[Main.hs](/uploads/1c2bf48faab46d8da7a7cc10bd50aaae/Main.hs)
[Main.hs.html](/uploads/da8184b460bc0d399de6f498997191ab/Main.hs.html)
## Expected behavior
`foo1` and `foo2` should be marked as "hit"
## Environment
* GHC version used: 8.8.1
Optional:
* Operating System: MacOS 10.14.6
* System Architecture: