Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haddock comments on un-named fields are not handled correctly #428

Closed
neongreen opened this issue Oct 29, 2019 · 6 comments · Fixed by #585
Closed

Haddock comments on un-named fields are not handled correctly #428

neongreen opened this issue Oct 29, 2019 · 6 comments · Fixed by #585
Labels
bug-upstream Something upstream is not working. comments Issues related to comment placement needs-ghc-patch To solve this issue we need to patch GHC

Comments

@neongreen
Copy link
Collaborator

neongreen commented Oct 29, 2019

Parsing of formatted code failed

Input:

data Foo
  = -- | Bar
    Bar
      Field1 -- ^ Field 1
      Field2 -- ^ Field 2

Error:

Parsing of formatted code failed:
  <stdin><rendered>:5:7-12
  parse error on input ‘Field1’

Output with --unsafe:

data Foo
  = -- | Bar
    Bar
      -- | Field 1
      Field1
      -- | Field 2
      Field2

The behavior of the Haddock parser is horrifying.

Lost comments

Input:

data Foo
  = -- | Bar
    Bar
      Field1 -- ^ Field 1

Output:

data Foo
  = -- | Bar
    Bar
      Field1
@neongreen neongreen added the bug Something isn't working label Oct 29, 2019
@neongreen
Copy link
Collaborator Author

Note: this is a minimized real-world example taken from GHC's sources.

@mrkkrp
Copy link
Member

mrkkrp commented Oct 30, 2019

Is this a bug in Ormolu or in Haddock? If latter, there is not much we can do except for reporting it.

@neongreen
Copy link
Collaborator Author

Well, it's a bug in GHC, essentially: haskell/haddock#1065.

The only way to work around it is to use -- ^ instead of -- |.

data Foo
  = Bar
    -- ^ Constructor
      Int
      -- ^ Field 1

I.e. for any constructors that have unnamed fields with haddocks, we will have to use this alternative syntax.

@neongreen
Copy link
Collaborator Author

As for the second issue (lost comments), yeah, it's possible that there's nothing we can do about it. We might be able to parse with and without Opt_Haddock and compare the trees, but I guess it's too much work.

@neongreen
Copy link
Collaborator Author

@mrkkrp mrkkrp added bug-upstream Something upstream is not working. and removed bug Something isn't working labels Oct 31, 2019
@mrkkrp
Copy link
Member

mrkkrp commented Mar 11, 2020

Related (almost the same issue): #445.

@mrkkrp mrkkrp added this to Harder in Google engagement Apr 9, 2020
@mrkkrp mrkkrp moved this from Harder to Backlog in Google engagement Apr 9, 2020
@mrkkrp mrkkrp added comments Issues related to comment placement needs-ghc-patch To solve this issue we need to patch GHC labels Apr 9, 2020
@mrkkrp mrkkrp moved this from Backlog to In progress in Google engagement May 12, 2020
@mrkkrp mrkkrp moved this from In progress to Done in Google engagement May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-upstream Something upstream is not working. comments Issues related to comment placement needs-ghc-patch To solve this issue we need to patch GHC
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants