Fix type equality roundtripping

pull/1/head
Lennart Spitzner 2016-08-04 11:18:31 +02:00
parent c6eb7a71b8
commit 982e19b8b9
2 changed files with 17 additions and 5 deletions

View File

@ -12,6 +12,7 @@ module Language.Haskell.Brittany.LayoutBasics
, rdrNameToText , rdrNameToText
, lrdrNameToText , lrdrNameToText
, lrdrNameToTextAnn , lrdrNameToTextAnn
, lrdrNameToTextAnnTypeEqualityIsSpecial
, askIndent , askIndent
, layoutWriteAppend , layoutWriteAppend
, layoutWriteAppendMultiline , layoutWriteAppendMultiline
@ -192,6 +193,15 @@ lrdrNameToTextAnn ast@(L _ n) = do
_ | any (hasUni AnnOpenP) aks -> Text.pack "(" <> t <> Text.pack ")" _ | any (hasUni AnnOpenP) aks -> Text.pack "(" <> t <> Text.pack ")"
_ | otherwise -> t _ | otherwise -> t
lrdrNameToTextAnnTypeEqualityIsSpecial
:: (MonadMultiReader Config m, MonadMultiReader (Map AnnKey Annotation) m)
=> GenLocated SrcSpan RdrName
-> m Text
lrdrNameToTextAnnTypeEqualityIsSpecial ast = do
x <- lrdrNameToTextAnn ast
return $ if x == Text.pack "Data.Type.Equality~"
then Text.pack "~" -- rraaaahhh special casing rraaahhhhhh
else x
askIndent :: (MonadMultiReader Config m) => m Int askIndent :: (MonadMultiReader Config m) => m Int
askIndent = runIdentity . _lconfig_indentAmount . _conf_layout <$> mAsk askIndent = runIdentity . _lconfig_indentAmount . _conf_layout <$> mAsk
@ -369,6 +379,7 @@ layoutWriteEnsureNewlineBlock = do
Right i -> Right $ max 1 i Right i -> Right $ max 1 i
, _lstate_addSepSpace = Just $ _lstate_baseY state , _lstate_addSepSpace = Just $ _lstate_baseY state
, _lstate_inhibitMTEL = False , _lstate_inhibitMTEL = False
, _lstate_commentCol = Nothing
} }
layoutWriteEnsureBlock :: (MonadMultiWriter layoutWriteEnsureBlock :: (MonadMultiWriter

View File

@ -29,7 +29,7 @@ layoutType :: ToBriDoc HsType
layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
-- _ | traceShow (ExactPrint.Types.mkAnnKey ltype) False -> error "impossible" -- _ | traceShow (ExactPrint.Types.mkAnnKey ltype) False -> error "impossible"
HsTyVar name -> do HsTyVar name -> do
let t = lrdrNameToText name t <- lrdrNameToTextAnn name
docLit t docLit t
HsForAllTy bndrs (L _ (HsQualTy (L _ cntxts@(_:_)) typ2)) -> do HsForAllTy bndrs (L _ (HsQualTy (L _ cntxts@(_:_)) typ2)) -> do
typeDoc <- docSharedWrapper layoutType typ2 typeDoc <- docSharedWrapper layoutType typ2
@ -284,7 +284,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
HsAppsTy [L _ (HsAppPrefix typ1)] -> do HsAppsTy [L _ (HsAppPrefix typ1)] -> do
typeDoc1 <- docSharedWrapper layoutType typ1 typeDoc1 <- docSharedWrapper layoutType typ1
typeDoc1 typeDoc1
HsAppsTy [L l (HsAppInfix name)] -> do HsAppsTy [_lname@(L _ (HsAppInfix name))] -> do
-- this redirection is somewhat hacky, but whatever. -- this redirection is somewhat hacky, but whatever.
-- TODO: a general problem when doing deep inspections on -- TODO: a general problem when doing deep inspections on
-- the type (and this is not the only instance) -- the type (and this is not the only instance)
@ -292,8 +292,9 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
-- the middle constructors. i have no idea under which -- the middle constructors. i have no idea under which
-- circumstances exactly important annotations (comments) -- circumstances exactly important annotations (comments)
-- would be assigned to such constructors. -- would be assigned to such constructors.
typeDoc1 <- docSharedWrapper layoutType $ (L l $ HsTyVar name) typeDoc1 <- -- docSharedWrapper layoutType $ (L l $ HsTyVar name)
typeDoc1 lrdrNameToTextAnnTypeEqualityIsSpecial name
docLit typeDoc1
HsAppsTy (L _ (HsAppPrefix typHead):typRestA) HsAppsTy (L _ (HsAppPrefix typHead):typRestA)
| Just typRest <- mapM (\case L _ (HsAppPrefix t) -> Just t | Just typRest <- mapM (\case L _ (HsAppPrefix t) -> Just t
_ -> Nothing) typRestA -> do _ -> Nothing) typRestA -> do
@ -316,7 +317,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
] ]
where where
layoutAppType (L _ (HsAppPrefix t)) = layoutType t layoutAppType (L _ (HsAppPrefix t)) = layoutType t
layoutAppType (L _ (HsAppInfix t)) = docLit =<< lrdrNameToTextAnn t layoutAppType (L _ (HsAppInfix t)) = docLit =<< lrdrNameToTextAnnTypeEqualityIsSpecial t
HsListTy typ1 -> do HsListTy typ1 -> do
typeDoc1 <- docSharedWrapper layoutType typ1 typeDoc1 <- docSharedWrapper layoutType typ1
docAlt docAlt