Commit 8dc29448 authored by Alan Zimmerman's avatar Alan Zimmerman Committed by Austin Seipp

API Annotations : ExprWithTySig processing discards annotated spans

In RdrHsSyn.checkAPat the processing for ExprWithTySig is defined as

   ExprWithTySig e t _ -> do e <- checkLPat msg e
                             -- Pattern signatures are parsed as sigtypes,
                             -- but they aren't explicit forall points.  Hence
                             -- we have to remove the implicit forall here.
                             let t' = case t of
                                        L _ (HsForAllTy Implicit _ _
                                             (L _ []) ty) -> ty
                                        other -> other
                             return (SigPatIn e (mkHsWithBndrs t'))

The t' variable ends up losing its original SrcSpan in the first case
branch. This results in annotations becoming detached from the AST.

Reviewed By: austin

Differential Revision: https://phabricator.haskell.org/D823

GHC Trac Issues: #10255
parent 79bfe27d
......@@ -847,7 +847,8 @@ checkAPat msg loc e0 = do
L _ (HsForAllTy Implicit _ _
(L _ []) ty) -> ty
other -> other
return (SigPatIn e (mkHsWithBndrs t'))
return (SigPatIn e (mkHsWithBndrs
(L (getLoc t) (HsParTy t'))))
-- n+k patterns
OpApp (L nloc (HsVar n)) (L _ (HsVar plus)) _
......
......@@ -3,6 +3,7 @@ parseTree
comments
exampleTest
listcomps
t10255
*.hi
*.o
*.run.*
......
......@@ -31,4 +31,9 @@ listcomps:
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc listcomps
./listcomps "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: clean annotations parseTree comments exampleTest listcomps
t10255:
rm -f t10255.o t10255.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10255
./t10255 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: clean annotations parseTree comments exampleTest listcomps t10255
Test10255.hs:1:14: Warning:
-XPatternSignatures is deprecated: use -XScopedTypeVariables or pragma {-# LANGUAGE ScopedTypeVariables #-} instead
---Problems---------------------
[
(AK <no location info> AnnEofPos = [Test10255.hs:8:1])
]
--------------------------------
[
(AK Test10255.hs:1:1 AnnModule = [Test10255.hs:2:1-6])
(AK Test10255.hs:1:1 AnnWhere = [Test10255.hs:2:18-22])
(AK Test10255.hs:4:1-17 AnnImport = [Test10255.hs:4:1-6])
(AK Test10255.hs:4:1-17 AnnSemi = [Test10255.hs:6:1])
(AK Test10255.hs:(6,1)-(7,11) AnnEqual = [Test10255.hs:6:29])
(AK Test10255.hs:(6,1)-(7,11) AnnFunId = [Test10255.hs:6:1-3])
(AK Test10255.hs:(6,1)-(7,11) AnnSemi = [Test10255.hs:8:1])
(AK Test10255.hs:6:5-27 AnnCloseP = [Test10255.hs:6:27])
(AK Test10255.hs:6:5-27 AnnOpenP = [Test10255.hs:6:5])
(AK Test10255.hs:6:6-26 AnnDcolon = [Test10255.hs:6:8-9])
(AK Test10255.hs:6:11-26 AnnCloseP = [Test10255.hs:6:26])
(AK Test10255.hs:6:11-26 AnnOpenP = [Test10255.hs:6:11])
(AK Test10255.hs:6:12-25 AnnRarrow = [Test10255.hs:6:20-21])
(AK <no location info> AnnEofPos = [Test10255.hs:8:1])
]
{-# LANGUAGE PatternSignatures #-}
module Test10255 where
import Data.Maybe
fob (f :: (Maybe t -> Int)) =
undefined
......@@ -3,3 +3,4 @@ test('parseTree', normal, run_command, ['$MAKE -s --no-print-directory parseTr
test('comments', normal, run_command, ['$MAKE -s --no-print-directory comments'])
test('exampleTest', normal, run_command, ['$MAKE -s --no-print-directory exampleTest'])
test('listcomps', normal, run_command, ['$MAKE -s --no-print-directory listcomps'])
test('T10255', normal, run_command, ['$MAKE -s --no-print-directory t10255'])
{-# LANGUAGE RankNTypes #-}
-- This program must be called with GHC's libdir as the single command line
-- argument.
module Main where
-- import Data.Generics
import Data.Data
import Data.List
import System.IO
import GHC
import BasicTypes
import DynFlags
import MonadUtils
import Outputable
import ApiAnnotation
import Bag (filterBag,isEmptyBag)
import System.Directory (removeFile)
import System.Environment( getArgs )
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Dynamic ( fromDynamic,Dynamic )
main::IO()
main = do
[libdir] <- getArgs
testOneFile libdir "Test10255"
testOneFile libdir fileName = do
((anns,cs),p) <- runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
setSessionDynFlags dflags
let mn =mkModuleName fileName
addTarget Target { targetId = TargetModule mn
, targetAllowObjCode = True
, targetContents = Nothing }
load LoadAllTargets
modSum <- getModSummary mn
p <- parseModule modSum
return (pm_annotations p,p)
let spans = Set.fromList $ getAllSrcSpans (pm_parsed_source p)
problems = filter (\(s,a) -> not (Set.member s spans))
$ getAnnSrcSpans (anns,cs)
putStrLn "---Problems---------------------"
putStrLn (intercalate "\n" [showAnns $ Map.fromList $ map snd problems])
putStrLn "--------------------------------"
putStrLn (intercalate "\n" [showAnns anns])
where
getAnnSrcSpans :: ApiAnns -> [(SrcSpan,(ApiAnnKey,[SrcSpan]))]
getAnnSrcSpans (anns,_) = map (\a@((ss,_),_) -> (ss,a)) $ Map.toList anns
getAllSrcSpans :: (Data t) => t -> [SrcSpan]
getAllSrcSpans ast = everything (++) ([] `mkQ` getSrcSpan) ast
where
getSrcSpan :: SrcSpan -> [SrcSpan]
getSrcSpan ss = [ss]
showAnns anns = "[\n" ++ (intercalate "\n"
$ map (\((s,k),v)
-> ("(AK " ++ pp s ++ " " ++ show k ++" = " ++ pp v ++ ")\n"))
$ Map.toList anns)
++ "]\n"
pp a = showPpr unsafeGlobalDynFlags a
-- ---------------------------------------------------------------------
-- Copied from syb for the test
-- | Generic queries of type \"r\",
-- i.e., take any \"a\" and return an \"r\"
--
type GenericQ r = forall a. Data a => a -> r
-- | Make a generic query;
-- start from a type-specific case;
-- return a constant otherwise
--
mkQ :: ( Typeable a
, Typeable b
)
=> r
-> (b -> r)
-> a
-> r
(r `mkQ` br) a = case cast a of
Just b -> br b
Nothing -> r
-- | Summarise all nodes in top-down, left-to-right order
everything :: (r -> r -> r) -> GenericQ r -> GenericQ r
-- Apply f to x to summarise top-level node;
-- use gmapQ to recurse into immediate subterms;
-- use ordinary foldl to reduce list of intermediate results
everything k f x = foldl k (f x) (gmapQ (everything k f) x)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment