[Git][ghc/ghc][ghc-9.0] API Annotations: Fix annotation for strictness

Ben Gamari gitlab at gitlab.haskell.org
Mon Sep 21 00:45:19 UTC 2020



Ben Gamari pushed to branch ghc-9.0 at Glasgow Haskell Compiler / GHC


Commits:
f91ea170 by Alan Zimmerman at 2020-09-20T19:25:22+01:00
API Annotations: Fix annotation for strictness

This adds the correct location for a ! or ~.

It is a reconstruction of 3ccc80ee6120db7ead579c6e9fc5c2164f3bf575,
some of which got mangled in the backport process.

- - - - -


1 changed file:

- compiler/GHC/Parser/PostProcess.hs


Changes:

=====================================
compiler/GHC/Parser/PostProcess.hs
=====================================
@@ -1374,19 +1374,24 @@ pBangTy lt@(L l1 _) xs =
     Nothing -> (False, lt, pure (), xs)
     Just (l2, anns, prag, unpk, xs') ->
       let bl = combineSrcSpans l1 l2
-          bt = addUnpackedness (prag, unpk) lt
-      in (True, L bl bt, addAnnsAt bl anns, xs')
+          (anns2, bt) = addUnpackedness (prag, unpk) lt
+      in (True, L bl bt, addAnnsAt bl (anns ++ anns2), xs')
 
 mkBangTy :: SrcStrictness -> LHsType GhcPs -> HsType GhcPs
 mkBangTy strictness =
   HsBangTy noExtField (HsSrcBang NoSourceText NoSrcUnpack strictness)
 
-addUnpackedness :: (SourceText, SrcUnpackedness) -> LHsType GhcPs -> HsType GhcPs
-addUnpackedness (prag, unpk) (L _ (HsBangTy x bang t))
+addUnpackedness :: (SourceText, SrcUnpackedness) -> LHsType GhcPs -> ([AddAnn], HsType GhcPs)
+addUnpackedness (prag, unpk) (L l (HsBangTy x bang t))
   | HsSrcBang NoSourceText NoSrcUnpack strictness <- bang
-  = HsBangTy x (HsSrcBang prag unpk strictness) t
+  = let
+      anns = case strictness of
+        SrcLazy     -> [AddAnn AnnTilde (srcSpanFirstCharacter l)]
+        SrcStrict   -> [AddAnn AnnBang  (srcSpanFirstCharacter l)]
+        NoSrcStrict -> []
+    in (anns, HsBangTy x (HsSrcBang prag unpk strictness) t)
 addUnpackedness (prag, unpk) t
-  = HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t
+  = ([], HsBangTy noExtField (HsSrcBang prag unpk NoSrcStrict) t)
 
 -- | Merge a /reversed/ and /non-empty/ soup of operators and operands
 --   into a type.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f91ea170d86fab45a9f4658b8b02f4adede9aef7

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f91ea170d86fab45a9f4658b8b02f4adede9aef7
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200920/c591c2a1/attachment-0001.html>


More information about the ghc-commits mailing list