Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hindent introduces parse errors in constraints for a default method #492

Open
JustusAdam opened this issue Mar 26, 2018 · 3 comments
Open

Comments

@JustusAdam
Copy link

Hindent misformats the end of a long constraint section in default method signatures in type class declarations.

I've had this happen in multiple type class declarations, here's just one example

class HasEnvExpr m =>
      MonadRecordEnvExpr m
    where
    addEnvExpression :: EnvExpr m -> m HostExpr
    default addEnvExpression :: ( MonadTrans t
                                , Monad n
                                , MonadRecordEnvExpr n
                                , t n ~ m
                                , EnvExpr m ~ EnvExpr n
    ) => -- <- this is outdented too much. This is a parse error for GHC
        EnvExpr m -> m HostExpr
@michalrus
Copy link

Any progress with this? Or maybe how to avoid that? I guess turning it off for a fragment would help, cf.

@michalrus
Copy link

For the time being, we’re running this after Hindent…

#!/bin/sh

set -o errexit

cd -P -- "$(dirname -- "$0")"

# <https://github.com/chrisdone/hindent/issues/492>
if [ "$1" = "backend-common/src/Backend/Log/Class.hs" ] ; then
  sed 's/^  ) =>/  \0/' -i "$1"
fi

@JustusAdam JustusAdam changed the title Hindent instroduces parse errors in constraints for a default method Hindent introduces parse errors in constraints for a default method Sep 24, 2019
@toku-sa-n
Copy link
Collaborator

While the current master no longer raises a parse error, it fails to align the indent. Below is the current output against the given input.

class HasEnvExpr m =>
      MonadRecordEnvExpr m
  where
  addEnvExpression :: EnvExpr m -> m HostExpr
  default addEnvExpression :: ( MonadTrans t
                              , Monad n
                              , MonadRecordEnvExpr n
                              , t n ~ m
                              , EnvExpr m ~ EnvExpr n
                              ) =>
    EnvExpr m -> m HostExpr

It aligns parameters if the signature is outside of a class declaration.

addEnvExpression ::
     ( MonadTrans t
     , Monad n
     , MonadRecordEnvExpr n
     , t n ~ m
     , EnvExpr m ~ EnvExpr n
     )
  => EnvExpr m
  -> m HostExpr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants