Closed plcplc closed 2 years ago
With --output-on-errors
you can see the source of the issue.
$ brittany --output-on-errors < foo.hs
ERROR: brittany pretty printer returned syntactically invalid result.
ERROR: encountered unknown syntactical constructs:
HsOpTy{} at stdin:(7,3)-(8,5)
{-# LANGUAGE TypeOperators #-}
module HsOpTy where
import GHC.TypeLits
type Foo = {- BRITTANY ERROR UNHANDLED SYNTACTICAL CONSTRUCT -}
Looks like there is some in progress work here. https://github.com/lspitzner/brittany/blob/master/src/Language/Haskell/Brittany/Internal/Layouters/Type.hs#L473-L532
FYI, that was reached with the --dump-ast-unknown
flag.
brittany --dump-ast-unknown < foo.hs
---- ast ----
A Just (Ann (DP (1,2)) [] [] [] Nothing Nothing)
HsOpTy
NoExt
A Just (Ann (DP (0,0)) [] [] [] Nothing Nothing)
HsTyVar
NoExt
NotPromoted
A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
Unqual {OccName: Int}
A Just (Ann (DP (0,1)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
Exact {abstract:Name}
A Just (Ann (DP (1,2)) [] [] [((G AnnSimpleQuote),DP (0,0)),((G AnnOpenS),DP (0,0)),((G AnnCloseS),DP (0,0))] Nothing Nothing)
HsExplicitListTy NoExt Promoted []
ERROR: brittany pretty printer returned syntactically invalid result.
ERROR: encountered unknown syntactical constructs:
HsOpTy{} at stdin:(7,3)-(8,5)
HsOpTy NoExt (HsTyVar NoExt NotPromoted (Unqual {OccName: Int})) (Exact {abstract:Name}) (HsExplicitListTy NoExt Promoted [])
The main problem seems to be the presence of newlines. briDocByExactInlineOnly
is being used, which explodes if newlines exist in the AST. So your code above fails, but this works.
{-# LANGUAGE TypeOperators #-}
module HsOpTy where
import GHC.TypeLits
type Foo = Int : '[]
If you can't omit newlines as a work around, I'd recommend using -- brittany-disable-next-binding
to disable formatting on that statement in the meantime.
{-# LANGUAGE TypeOperators #-}
module HsOpTy where
import GHC.TypeLits
-- brittany-disable-next-binding
type Foo =
Int :
'[]
I just bumped into this and made a simple test case. Interestingly moving this comma to the next line is enough to stop this happening :/
-- Works
a :: (a
,b + c)
-- Fails with the error mentioned above
a :: (a,
b + c)
This may be another good fit for https://github.com/lspitzner/brittany/issues/28 (passthrough for unhandled constructs)
@expipiplus1 Thanks for the hint! #28 was in fact implemented by now. So on current master, the effect of this not being fully supported yet is much more limited.
Great!
I think I'm experiencing the same issue with servant
here.
https://github.com/theam/aws-lambda-haskell-runtime/blob/master/examples/wai-app/src/Lib.hs#L60-L66
Any news related to this issue? Is there any help required? This issue actually blocks from using brittany
on production projects and unfortunately forces to switch to ormolu
without such a problems, but with an alien formatting style instead.
I'm closing this in favor of #241, which I think is the same thing.
Currently, running brittany over the below file:
... results in the below error:
Note that when the definition of
type Foo
is just a single line brittany doesn't seem to mind.Concretely, this is an issue for me in Servant API type definitions, which can get lengthy.