haskell / haskell/stylish-haskell
Trouble formatting data declaration where there is no space between field name and ::
- Dominant language
- Haskell
- Stars
- 1k
- Forks
- 153
- PR merge metrics
- No merged PRs in 30d
Description
(moved from https://github.com/haskell/haskell-language-server/issues/4466)
### Behavior summary by stylish-haskell version(s):
* 0.14.6.0 - `Main.hs: :5:6: error: parse error on input `:'`
* 0.13.0.0 - `Main.hs: RealSrcSpan SrcSpanOneLine "Main.hs" 5 6 7: parse error on input `:'`
* 0.12.0.0 - `Main.hs: RealSrcSpan SrcSpanOneLine "Main.hs" 5 6 7: parse error on input `:'`
* 0.11.0.0 - `Language.Haskell.Stylish.Parse.parseModule: could not parse Main.hs: ParseFailed (SrcLoc ".hs" 5 6) "Parse error: :"`
* 0.10.0.0 - Successful parse and formatting!
### Steps to reproduce
Format
`Main.hs`:
```haskell
main = pure ()
data MyRecord = MyRecord
{ ab :: Int
, c:: Int
}
```
with `stylish-haskell Main.hs`
Important pieces here:
* `c:: Int` <- no space between field name and `::`. This makes the formatting fail.
* `ab` field name is longer than `c` field name. This makes the error show up in the LSP log. If the fields are the same length no error appears, but the formatting still fails to apply. Weird!
### Expected behaviour
Since this code compiles with `ghc Main.hs` I would expect it to be formatted with `stylish-haskell Main.hs`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the failure with the Main.hs example and stylish-haskell, then inspect the parsing and formatting path for record declarations. Compare the handling of `ab :: Int` and `c:: Int`; done means the example formats successfully while preserving valid Haskell syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100