diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2015-05-11 15:28:55 +0200 |
---|---|---|
committer | Alan Zimmerman <alan.zimm@gmail.com> | 2015-05-11 15:28:55 +0200 |
commit | fe38195eb783fc2f2f2d5ef50fb665b06fd15e82 (patch) | |
tree | 6881106397d6930ff4af336db7949a12f7435787 /testsuite/tests/ghc-api | |
parent | f35d621de401bea74d42b28ff9a1d8c5d963a92d (diff) | |
download | haskell-fe38195eb783fc2f2f2d5ef50fb665b06fd15e82.tar.gz |
ApiAnnotations : pquals production adds AnnVbar in the wrong place
Summary:
The Parser.y production for pquals is
pquals :: { Located [[LStmt RdrName (LHsExpr RdrName)]] }
: squals '|' pquals
{% addAnnotation (gl $ last $ unLoc $1) AnnVbar (gl $2) >>
return (sLL $1 $> (reverse (unLoc $1) : unLoc $3)) }
| squals { L (getLoc $1) [reverse (unLoc $1)] }
The squals are returned in reverse order, so the AnnVbar should be
attached to the head of the list, not the last.
Test Plan: ./validate
Reviewers: hvr, austin
Reviewed By: austin
Subscribers: thomie, mpickering
Differential Revision: https://phabricator.haskell.org/D869
GHC Trac Issues: #10357
Diffstat (limited to 'testsuite/tests/ghc-api')
-rw-r--r-- | testsuite/tests/ghc-api/annotations/.gitignore | 1 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/Makefile | 8 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/T10357.stderr | 30 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/T10357.stdout | 110 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/Test10357.hs | 13 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/all.T | 1 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/t10357.hs | 118 |
7 files changed, 281 insertions, 0 deletions
diff --git a/testsuite/tests/ghc-api/annotations/.gitignore b/testsuite/tests/ghc-api/annotations/.gitignore index 79e26095de..4f6f3be153 100644 --- a/testsuite/tests/ghc-api/annotations/.gitignore +++ b/testsuite/tests/ghc-api/annotations/.gitignore @@ -4,6 +4,7 @@ comments exampleTest listcomps t10309 +t10357 t10255 t10268 t10269 diff --git a/testsuite/tests/ghc-api/annotations/Makefile b/testsuite/tests/ghc-api/annotations/Makefile index c181ef09a0..0cebeaf1db 100644 --- a/testsuite/tests/ghc-api/annotations/Makefile +++ b/testsuite/tests/ghc-api/annotations/Makefile @@ -10,6 +10,7 @@ clean: rm -f t1037 rm -f t10309 rm -f listcomps boolFormula + rm -f t10357 annotations: rm -f annotations.o annotations.hi @@ -41,6 +42,13 @@ t10255: '$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10255 ./t10255 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" +t10357: + rm -f t10357.o t10357.hi + '$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10357 + ./t10357 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" + +.PHONY: t10357 + .PHONY: clean annotations parseTree comments exampleTest listcomps t10255 T10268: diff --git a/testsuite/tests/ghc-api/annotations/T10357.stderr b/testsuite/tests/ghc-api/annotations/T10357.stderr new file mode 100644 index 0000000000..a418490766 --- /dev/null +++ b/testsuite/tests/ghc-api/annotations/T10357.stderr @@ -0,0 +1,30 @@ + +Test10357.hs:4:13: error: Not in scope: ‘one’ + +Test10357.hs:4:19: error: Not in scope: ‘x’ + +Test10357.hs:5:7: error: Not in scope: ‘multPoly’ + +Test10357.hs:6:10: error: Not in scope: ‘poly’ + +Test10357.hs:6:15: error: + Not in scope: data constructor ‘LE’ + Perhaps you meant ‘LT’ (imported from Prelude) + +Test10357.hs:7:10: error: Not in scope: ‘addPoly’ + +Test10357.hs:7:19: error: Not in scope: ‘poly’ + +Test10357.hs:7:24: error: + Not in scope: data constructor ‘LE’ + Perhaps you meant ‘LT’ (imported from Prelude) + +Test10357.hs:7:43: error: Not in scope: ‘multPoly’ + +Test10357.hs:8:19: error: Not in scope: ‘poly’ + +Test10357.hs:8:24: error: + Not in scope: data constructor ‘LE’ + Perhaps you meant ‘LT’ (imported from Prelude) + +Test10357.hs:8:43: error: Not in scope: ‘multPoly’ diff --git a/testsuite/tests/ghc-api/annotations/T10357.stdout b/testsuite/tests/ghc-api/annotations/T10357.stdout new file mode 100644 index 0000000000..03862b2ee9 --- /dev/null +++ b/testsuite/tests/ghc-api/annotations/T10357.stdout @@ -0,0 +1,110 @@ +---Problems--------------------- +[ +(AK <no location info> AnnEofPos = [Test10357.hs:14:1]) +] + +---Problems'-------------------- +[(AnnEofPos, Test10357.hs:14:1)] +-------------------------------- +[ +(AK Test10357.hs:1:1 AnnModule = [Test10357.hs:2:1-6]) + +(AK Test10357.hs:1:1 AnnWhere = [Test10357.hs:2:18-22]) + +(AK Test10357.hs:(4,1)-(13,5) AnnEqual = [Test10357.hs:4:11]) + +(AK Test10357.hs:(4,1)-(13,5) AnnFunId = [Test10357.hs:4:1-9]) + +(AK Test10357.hs:(4,1)-(13,5) AnnSemi = [Test10357.hs:14:1]) + +(AK Test10357.hs:4:13-19 AnnVal = [Test10357.hs:4:17]) + +(AK Test10357.hs:(4,13)-(13,5) AnnVal = [Test10357.hs:4:21]) + +(AK Test10357.hs:(5,5)-(13,5) AnnCloseS = [Test10357.hs:13:5]) + +(AK Test10357.hs:(5,5)-(13,5) AnnOpenS = [Test10357.hs:5:5]) + +(AK Test10357.hs:(5,5)-(13,5) AnnVbar = [Test10357.hs:10:5]) + +(AK Test10357.hs:6:9-34 AnnCloseP = [Test10357.hs:6:34]) + +(AK Test10357.hs:6:9-34 AnnOpenP = [Test10357.hs:6:9]) + +(AK Test10357.hs:6:18-33 AnnCloseS = [Test10357.hs:6:33]) + +(AK Test10357.hs:6:18-33 AnnOpenS = [Test10357.hs:6:18]) + +(AK Test10357.hs:6:25-32 AnnCloseP = [Test10357.hs:6:32]) + +(AK Test10357.hs:6:25-32 AnnOpenP = [Test10357.hs:6:25]) + +(AK Test10357.hs:6:26-31 AnnVal = [Test10357.hs:6:29]) + +(AK Test10357.hs:(7,9)-(9,9) AnnCloseP = [Test10357.hs:9:9]) + +(AK Test10357.hs:(7,9)-(9,9) AnnOpenP = [Test10357.hs:7:9]) + +(AK Test10357.hs:7:18-57 AnnCloseP = [Test10357.hs:7:57]) + +(AK Test10357.hs:7:18-57 AnnOpenP = [Test10357.hs:7:18]) + +(AK Test10357.hs:7:19-56 AnnVal = [Test10357.hs:7:43-52]) + +(AK Test10357.hs:7:27-41 AnnCloseS = [Test10357.hs:7:41]) + +(AK Test10357.hs:7:27-41 AnnOpenS = [Test10357.hs:7:27]) + +(AK Test10357.hs:7:28 AnnComma = [Test10357.hs:7:29]) + +(AK Test10357.hs:7:31-36 AnnVal = [Test10357.hs:7:33]) + +(AK Test10357.hs:7:31-40 AnnVal = [Test10357.hs:7:38]) + +(AK Test10357.hs:7:43-52 AnnBackquote = [Test10357.hs:7:43, Test10357.hs:7:52]) + +(AK Test10357.hs:7:43-52 AnnVal = [Test10357.hs:7:44-51]) + +(AK Test10357.hs:8:18-59 AnnCloseP = [Test10357.hs:8:59]) + +(AK Test10357.hs:8:18-59 AnnOpenP = [Test10357.hs:8:18]) + +(AK Test10357.hs:8:19-58 AnnVal = [Test10357.hs:8:43-52]) + +(AK Test10357.hs:8:37-41 AnnCloseS = [Test10357.hs:8:41]) + +(AK Test10357.hs:8:37-41 AnnOpenS = [Test10357.hs:8:37]) + +(AK Test10357.hs:8:38-40 AnnMinus = [Test10357.hs:8:38]) + +(AK Test10357.hs:8:43-52 AnnBackquote = [Test10357.hs:8:43, Test10357.hs:8:52]) + +(AK Test10357.hs:8:43-52 AnnVal = [Test10357.hs:8:44-51]) + +(AK Test10357.hs:10:7-20 AnnComma = [Test10357.hs:10:21]) + +(AK Test10357.hs:10:7-20 AnnLarrow = [Test10357.hs:10:13-14]) + +(AK Test10357.hs:10:16-20 AnnCloseS = [Test10357.hs:10:20]) + +(AK Test10357.hs:10:16-20 AnnDotdot = [Test10357.hs:10:18-19]) + +(AK Test10357.hs:10:16-20 AnnOpenS = [Test10357.hs:10:16]) + +(AK Test10357.hs:10:23-44 AnnLet = [Test10357.hs:10:23-25]) + +(AK Test10357.hs:10:23-44 AnnVbar = [Test10357.hs:11:5]) + +(AK Test10357.hs:10:27-44 AnnEqual = [Test10357.hs:10:30]) + +(AK Test10357.hs:10:27-44 AnnFunId = [Test10357.hs:10:27-28]) + +(AK Test10357.hs:11:7-29 AnnLarrow = [Test10357.hs:11:13-14]) + +(AK Test10357.hs:11:7-29 AnnVbar = [Test10357.hs:12:5]) + +(AK Test10357.hs:12:7-24 AnnLarrow = [Test10357.hs:12:13-14]) + +(AK <no location info> AnnEofPos = [Test10357.hs:14:1]) +] + diff --git a/testsuite/tests/ghc-api/annotations/Test10357.hs b/testsuite/tests/ghc-api/annotations/Test10357.hs new file mode 100644 index 0000000000..8790ca6c1b --- /dev/null +++ b/testsuite/tests/ghc-api/annotations/Test10357.hs @@ -0,0 +1,13 @@ +{-# LANGUAGE ParallelListComp #-} +module Test10357 where + +legendres = one : x : + [ multPoly + (poly LE [recip (n' + 1)]) + (addPoly (poly LE [0, 2 * n' + 1] `multPoly` p_n) + (poly LE [-n'] `multPoly` p_nm1) + ) + | n <- [1..], let n' = fromInteger n + | p_n <- tail legendres + | p_nm1 <- legendres + ] diff --git a/testsuite/tests/ghc-api/annotations/all.T b/testsuite/tests/ghc-api/annotations/all.T index 4709c2a2f5..5614127cf0 100644 --- a/testsuite/tests/ghc-api/annotations/all.T +++ b/testsuite/tests/ghc-api/annotations/all.T @@ -11,3 +11,4 @@ test('T10312', normal, run_command, ['$MAKE -s --no-print-directory t10312' test('T10307', normal, run_command, ['$MAKE -s --no-print-directory t10307']) test('T10309', normal, run_command, ['$MAKE -s --no-print-directory t10309']) test('boolFormula', normal, run_command, ['$MAKE -s --no-print-directory boolFormula']) +test('T10357', normal, run_command, ['$MAKE -s --no-print-directory t10357']) diff --git a/testsuite/tests/ghc-api/annotations/t10357.hs b/testsuite/tests/ghc-api/annotations/t10357.hs new file mode 100644 index 0000000000..93a1f701ee --- /dev/null +++ b/testsuite/tests/ghc-api/annotations/t10357.hs @@ -0,0 +1,118 @@ +{-# 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 "Test10357" + +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) + + exploded = [((kw,ss),[anchor]) + | ((anchor,kw),sss) <- Map.toList anns,ss <- sss] + + exploded' = Map.toList $ Map.fromListWith (++) exploded + + problems' = filter (\(_,anchors) + -> not (any (\a -> Set.member a spans) anchors)) + exploded' + + putStrLn "---Problems---------------------" + putStrLn (intercalate "\n" [showAnns $ Map.fromList $ map snd problems]) + putStrLn "---Problems'--------------------" + putStrLn (intercalate "\n" [pp $ Map.fromList $ map fst 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) |