tweag / ormolu

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

Misformats hanging kind signatures #749

Closed robx closed 3 years ago

robx commented 3 years ago

Describe the bug

With hanging kind signatures

data Thing
  :: Type
  -> Type

ormolu formats to unparseable code.

To Reproduce

$ cat test.hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}

module Vec where

import Data.Kind

data Ze
data Su n

data Vec
  :: Type
  -> Type
  -> Type
  where
    Nil  :: Vec a Ze
    Cons :: a -> Vec a n -> Vec a (Su n)

$ ormolu test.hs
test.hs:13:1
  Parsing of formatted code failed:  parse error (possibly incorrect indentation or mismatched brackets)
$ ormolu -u test.hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}

module Vec where

import Data.Kind

data Ze

data Su n

data Vec :: Type ->
Type ->
Type where
  Nil :: Vec a Ze
  Cons :: a -> Vec a n -> Vec a (Su n)

Expected behavior The code should be formatted to parseable code (with the same AST).

Environment current master (post-0.2) on macos

mrkkrp commented 3 years ago

Note: there should be a breakpoint after :: and an increase of indentation for the type signature that follows.