diff options
author | Alec Theriault <alec.theriault@gmail.com> | 2018-06-07 13:26:53 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-06-07 18:06:29 -0400 |
commit | 0361fc038e117befc3c59fcd589d640006407ed6 (patch) | |
tree | c7d38167a43fb4b099f4beeeb58056b8ca9db311 /compiler/parser/RdrHsSyn.hs | |
parent | efea32cf2c41d35f2ba5a79bf70cc7768b7b0fd5 (diff) | |
download | haskell-0361fc038e117befc3c59fcd589d640006407ed6.tar.gz |
Move 'HsBangTy' out in constructor arguments
When run with -haddock, a constructor argument can have both a a
strictness/unpackedness annotation and a docstring. The parser binds
'HsBangTy' more tightly than 'HsDocTy', yet for constructor arguments we
really need the 'HsBangTy' on the outside.
This commit does this shuffling in the 'mkConDeclH98' and 'mkGadtDecl'
smart constructors.
Test Plan: haddockA038, haddockC038
Reviewers: bgamari, dfeuer
Reviewed By: bgamari
Subscribers: dfeuer, rwbarton, thomie, carter
Differential Revision: https://phabricator.haskell.org/D4727
Diffstat (limited to 'compiler/parser/RdrHsSyn.hs')
-rw-r--r-- | compiler/parser/RdrHsSyn.hs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs index dfcccd369e..35371af9c8 100644 --- a/compiler/parser/RdrHsSyn.hs +++ b/compiler/parser/RdrHsSyn.hs @@ -626,8 +626,10 @@ mkConDeclH98 name mb_forall mb_cxt args , con_forall = isJust mb_forall , con_ex_tvs = mb_forall `orElse` [] , con_mb_cxt = mb_cxt - , con_args = args + , con_args = args' , con_doc = Nothing } + where + args' = nudgeHsSrcBangs args mkGadtDecl :: [Located RdrName] -> LHsType GhcPs -- Always a HsForAllTy @@ -638,7 +640,7 @@ mkGadtDecl names ty , con_forall = isLHsForAllTy ty , con_qvars = mkHsQTvs tvs , con_mb_cxt = mcxt - , con_args = args + , con_args = args' , con_res_ty = res_ty , con_doc = Nothing } where @@ -651,6 +653,7 @@ mkGadtDecl names ty split_rho tau = (Nothing, tau) (args, res_ty) = split_tau tau + args' = nudgeHsSrcBangs args -- See Note [GADT abstract syntax] in HsDecls split_tau (L _ (HsFunTy _ (L loc (HsRecTy _ rf)) res_ty)) @@ -658,6 +661,28 @@ mkGadtDecl names ty split_tau (L _ (HsParTy _ ty)) = split_tau ty split_tau tau = (PrefixCon [], tau) +nudgeHsSrcBangs :: HsConDeclDetails GhcPs -> HsConDeclDetails GhcPs +-- ^ This function ensures that fields with strictness or packedness +-- annotations put these annotations on an outer 'HsBangTy'. +-- +-- The problem is that in the parser, strictness and packedness annotations +-- bind more tightly that docstrings. However, the expectation downstream of +-- the parser (by functions such as 'getBangType' and 'getBangStrictness') +-- is that docstrings bind more tightly so that 'HsBangTy' may end up as the +-- top-level type. +-- +-- See #15206 +nudgeHsSrcBangs details + = case details of + PrefixCon as -> PrefixCon (map go as) + RecCon r -> RecCon r + InfixCon a1 a2 -> InfixCon (go a1) (go a2) + where + go (L l (HsDocTy _ (L _ (HsBangTy _ s lty)) lds)) = + L l (HsBangTy noExt s (addCLoc lty lds (HsDocTy noExt lty lds))) + go lty = lty + + setRdrNameSpace :: RdrName -> NameSpace -> RdrName -- ^ This rather gruesome function is used mainly by the parser. -- When parsing: |