Closed tomjaguarpaw closed 1 year ago
Thanks for the report! The problem is that in the input, the AST contains a Haddock comment (HsDoc
construct) with text " "
, but the output does not contain a Haddock comment (you can eg see this on Ormolu Live with the "Show internal parse result" option), so the AST diffing reports an error. This somewhat surprising behavior of the GHC parser already came up in #726, and was fixed in #818 by removing all Haddock comments that are completely blank. #818 was missing that operation for Haddock comments in data declarations, which I added in #1068, which fixes this issue.
Hence, with #1068, your example
data T = T {- ^ -}
is formatted to
data T = T
Hope this makes sense!
Thanks for your response @amesgen.
Hope this makes sense!
It makes sense but I think it's the wrong thing to do. See https://github.com/tweag/ormolu/pull/1068#issuecomment-1707205055
Personally I would prefer the approach that AST diffing considers comments consisting of only of any amount of whitespace to be equivalent.
Or, if you want to keep AST diffing as it is, then I think that translating empty -- ^
to empty -- |
, but deleting empty {- ^ -}
would be satisfactory, because it would provide the escape hatch of using -- |
/-- ^
as an alternative to {- ^ -}
.
(Just FTR: There is additional discussion in #1068)
Describe the bug
If I have an empty
{- ^ -}
Haddock annotation thenormolu
fails with anAST of input and AST of formatted code differ
error.To Reproduce
Expected behavior
ormolu
to produce the same reformatted code as above but to not complain that the ASTs differ (I don't think they do!).{- ^ ... -}
is not mentioned in the Haddock documentation as valid Haddock syntax, but it does accept it. Note that if there is text in the markup then everything is fine:Environment
Additional context
ormolu
is great, thanks!Perhaps related: https://github.com/tweag/ormolu/issues/822