ennocramer / floskell

Floskell is a flexible Haskell source code pretty printer.
BSD 3-Clause "New" or "Revised" License
178 stars 22 forks source link

Record Dot Syntax conflicts #63

Open Dessix opened 3 years ago

Dessix commented 3 years ago

When using Record Dot Syntax, Floskell is willing to break the code:

By default, this breaks when formatted with the base and cramer styles, and any others which do not use a workaround:

askAppCommand :: RIO App CliCommand
askAppCommand = do
  env <- ask @App
  return $ env.appCommand
  -- Gets replaced with:
  -- return $ env . appCommand
  -- Which attempts to compose a record with its field accessor

But this workaround preserves compilation across format calls:

  "op": {
      ". in expression": {
        "force-linebreak": false,
        "spaces": "none",
        "linebreaks": "after"
      }
  }

... Unfortunately, that workaround immediately breaks most point-free code, including the below:

a . b . c
-- Gets replaced with:
-- a.b.c
-- Which attempts to access `a` as a record with field `b` having field `c`

So far as I can tell, there's no viable configuration that produces the intended behaviour in both scenarios.

ngua commented 3 years ago

I might be mistaken, but I don't think it would be possible for Floskell to support the new record dot syntax, at least for the moment. Floskell depends on haskell-src-exts for parsing Haskell sources, and that library won't be receiving updates anymore (and hasn't for a couple of years, I believe). RecordDotSyntax was implemented after its last update. I ran into a similar scenario with StandaloneKindSignatures, which causes a Floskell parse error when used.