invalid output when deriving instances for an associated newtype family instance #207

Closed
opened 2018-12-15 17:37:25 +01:00 by dspies-leapyear · 5 comments
dspies-leapyear commented 2018-12-15 17:37:25 +01:00 (Migrated from github.com)

Trying to format a typeclass instance which includes data-family declarations and getting:

Brittany error - invalid output

{-# LANGUAGE TypeFamilies #-}

module Lib where

class Foo x where
  data Bar x
  bar :: x -> Bar x

instance Foo () where
  newtype Bar () = Baz ()
    deriving (Eq, Ord, Show)
  bar = Baz
Trying to format a typeclass instance which includes data-family declarations and getting: `Brittany error - invalid output` ``` {-# LANGUAGE TypeFamilies #-} module Lib where class Foo x where data Bar x bar :: x -> Bar x instance Foo () where newtype Bar () = Baz () deriving (Eq, Ord, Show) bar = Baz ```
dspies-leapyear commented 2018-12-17 20:35:27 +01:00 (Migrated from github.com)

It looks like it's specifically deriving on a newtype that causes it to break. Updated with a MWE. PTAL

It looks like it's specifically `deriving` on a `newtype` that causes it to break. Updated with a MWE. PTAL
tfausak commented 2019-06-18 03:59:24 +02:00 (Migrated from github.com)

Seems like this only affects newtypes. Changing it to data works as expected.

-- succeeds
instance C () where
 data T () = T ()
  deriving Eq

-- fails
instance C () where
 newtype T () = T ()
  deriving Eq

-- using `--output-on-errors` gives
instance C () where
  newtype T () = T ()
  deriving Eq
Seems like this only affects `newtype`s. Changing it to `data` works as expected. ``` hs -- succeeds instance C () where data T () = T () deriving Eq -- fails instance C () where newtype T () = T () deriving Eq -- using `--output-on-errors` gives instance C () where newtype T () = T () deriving Eq ```
cdparks commented 2020-03-12 17:26:09 +01:00 (Migrated from github.com)

I ran into this not with deriving but with nesting the field selector on the next line. This module spits out a ERROR: brittany pretty printer returned syntactically invalid result:

class Foo a where
  data family Bar

instance Foo Int where
  newtype Bar Int = BarInt
    { unBarInt :: Int
    }

With --output-on-errors, I'm getting:

class Foo a where
  data family Bar

instance Foo Int where
  newtype Bar Int = BarInt
  { unBarInt :: Int
  }

Note that the position of the braces is now a syntax error.

@tfausak happy to file a separate bug or just pile onto this one

I ran into this not with `deriving` but with nesting the field selector on the next line. This module spits out a `ERROR: brittany pretty printer returned syntactically invalid result`: ```haskell class Foo a where data family Bar instance Foo Int where newtype Bar Int = BarInt { unBarInt :: Int } ``` With `--output-on-errors`, I'm getting: ```haskell class Foo a where data family Bar instance Foo Int where newtype Bar Int = BarInt { unBarInt :: Int } ``` Note that the position of the braces is now a syntax error. @tfausak happy to file a separate bug or just pile onto this one
tfausak commented 2020-03-12 18:27:58 +01:00 (Migrated from github.com)

Seems like it's probably the same root cause.

Seems like it's probably the same root cause.
lspitzner commented 2020-03-13 01:20:04 +01:00 (Migrated from github.com)
uh oh https://github.com/lspitzner/brittany/blob/4b673d1d9db70e3a0d01a6b3315618e30b887c78/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs#L1038-L1041
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hexagoxel/brittany#207
There is no content yet.