From 22361c4ecd3f576abdd4fcf06c8de40d044ebdbf Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Tue, 2 Nov 2021 02:17:05 +0000 Subject: [PATCH] Fix getting binders from `HsForAllTy` --- .../Haskell/Brittany/Internal/Layouters/Type.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Type.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Type.hs index 1804bc6..5af9b2d 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Type.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Type.hs @@ -48,7 +48,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of ] NotPromoted -> docWrapNode name $ docLit t HsForAllTy _ hsf (L _ (HsQualTy _ (L _ cntxts) typ2)) -> do - let bndrs = hsf_vis_bndrs hsf + let bndrs = getBinders hsf typeDoc <- docSharedWrapper layoutType typ2 tyVarDocs <- layoutTyVarBndrs bndrs cntxtDocs <- cntxts `forM` docSharedWrapper layoutType @@ -135,7 +135,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of ) ] HsForAllTy _ hsf typ2 -> do - let bndrs = hsf_vis_bndrs hsf + let bndrs = getBinders hsf typeDoc <- layoutType typ2 tyVarDocs <- layoutTyVarBndrs bndrs let maybeForceML = case typ2 of @@ -647,3 +647,15 @@ processTyVarBndrsSingleline bndrDocs = bndrDocs >>= \case , docForceSingleline $ doc , docLit $ Text.pack ")" ] + +getBinders :: HsForAllTelescope pass -> [LHsTyVarBndr () pass] +getBinders x = case x of + HsForAllVis _ b -> b + HsForAllInvis _ b -> fmap withoutSpecificity b + XHsForAllTelescope _ -> [] + +withoutSpecificity :: LHsTyVarBndr flag pass -> LHsTyVarBndr () pass +withoutSpecificity = fmap $ \ x -> case x of + UserTyVar a _ c -> UserTyVar a () c + KindedTyVar a _ c d -> KindedTyVar a () c d + XTyVarBndr a -> XTyVarBndr a