tweag/ormolu

Idempotency check fails for comment in import list

Opened this issue · 0 comments

Describe the bug
If there is a comment in an (empty) identifier list of an import declaration, the comment floats out (which is already unwanted), but on top of that, in certain situations it's not even idempotent.

To Reproduce
The issue in a non-empty identifier list even happens here:

import Package1
import Package3 (
 hi,
 -- , import1
 test,
 )
import Package2

If you change the 2 into a 6, it remains idempotent, so in this case it's the reordering that causes the issue, I think.

The issue within an empty identifier list happens here:

import Package1
import Package3 (
 -- , import1
 )
import Package2

Even if you change the 2 into something >= 4, it's still not idempotent. Removing the 2 though, does work.

Expected behavior
The comment should not float out of the identifier list. And the change should be idempotent.

Environment

  • Ubuntu 22.04
  • Forgot which version of Ormolu, tried it on Jul 11 2023 with the newest Fourmolu and tried the corresponding Ormolu to verify (which can be found here: fourmolu/fourmolu#349)