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

AST of input and AST of formatted code differ on certain empty comments #1159

Open
nikita-volkov opened this issue Feb 24, 2025 · 3 comments
Labels
bug Something isn't working comments Issues related to comment placement

Comments

@nikita-volkov
Copy link

Formatting the following code:

data A = A
  {
    -- |
    -- 
    a :: Int
  }

Results in the following error:

@@ -14,8 +14,6 @@
  data A = A
-   {
-     -- |
-     -- 
+   { -- |
      a :: Int
    }

  AST of input and AST of formatted code differ.
    at ***
  Please, consider reporting the bug.
  To format anyway, use --unsafe.

Environment

  • macOS 14.1.2
  • ormolu 0.7.7.0 using ghc-lib-parser 9.10.1.20240511
@amesgen amesgen added bug Something isn't working comments Issues related to comment placement labels Feb 24, 2025
@amesgen
Copy link
Member

amesgen commented Feb 24, 2025

Thanks, I think this is related to the special handling of empty Haddock comments, also see #1068 and #1065 and the upstream ticket https://gitlab.haskell.org/ghc/ghc/-/issues/23935

@nikita-volkov
Copy link
Author

Reproduced on:

ormolu 0.8.0.0 using ghc-lib-parser 9.12.1.20250105

@amesgen
Copy link
Member

amesgen commented Feb 24, 2025

FTR the problem here is that in

data A = A
  {
    -- |
    -- 
    a :: Int
  }

there is a space after --. That causes the GHC parser to not insert DocD; the comment only shows up as non-Haddock AST comment (see #901 (comment) for context); but in the output, it does, so the AST differs.

I think fixing this (in a non-adhoc manner) will either require https://gitlab.haskell.org/ghc/ghc/-/issues/23935 or a change to how we format Haddock comments, cf #901 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working comments Issues related to comment placement
Projects
None yet
Development

No branches or pull requests

2 participants