tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
938 stars 83 forks source link

Formatted file has invalid syntax for the associated type synonym defaults #1098

Closed lykahb closed 4 months ago

lykahb commented 4 months ago

Describe the bug Ormolu removes the word "instance" in the output.

To Reproduce Format this file

class IsBoolMap v where
  type Key v
  type instance Key v = Int

  lookupKey :: Key v -> v -> Maybe Bool

The output would be

class IsBoolMap v where
  type Key v
  type Key v = Int  -- Invalid syntax

  lookupKey :: Key v -> v -> Maybe Bool

Expected behavior This line preserves the word instance:

  type instance Key v = Int

Environment

amesgen commented 4 months ago

You write

class IsBoolMap v where
  type Key v
  type Key v = Int  -- Invalid syntax

AFAICT, both variants (with and without instance) are valid (they both parse and compile just fine). From the GHC User's Guide:

  • The instance keyword is optional.

Are you observing something different?

lykahb commented 4 months ago

I had an unrelated warning on that line and compiled with -Werror. At a glance the disappearing keyword looked like the source of it.