summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2015-05-11 17:57:05 +0200
committerAlan Zimmerman <alan.zimm@gmail.com>2015-05-11 17:57:05 +0200
commitecc3d6be218b1c7a36ee3f2f36c4f3ac4f45c34f (patch)
tree6ee3b29a729dfdb047d4b7768ed67384037c74dd /testsuite
parentfe38195eb783fc2f2f2d5ef50fb665b06fd15e82 (diff)
downloadhaskell-ecc3d6be218b1c7a36ee3f2f36c4f3ac4f45c34f.tar.gz
ApiAnnotations : PatBind gives wrong SrcSpan for the pattern.
Summary: The production for decl_no_th starts decl_no_th :: { Located (OrdList (LHsDecl RdrName)) } : sigdecl { $1 } | '!' aexp rhs {% do { let { e = sLL $1 $> (SectionR (sL1 $1 (HsVar bang_RDR)) $2) }; pat <- checkPattern empty e; ... The e value should be just the pattern, excluding the rhs, but the span created includes the rhs. Test Plan: ./validate Reviewers: hvr, austin Reviewed By: austin Subscribers: bgamari, thomie, mpickering Differential Revision: https://phabricator.haskell.org/D873 GHC Trac Issues: #10358
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/ghc-api/annotations/.gitignore1
-rw-r--r--testsuite/tests/ghc-api/annotations/Makefile7
-rw-r--r--testsuite/tests/ghc-api/annotations/T10358.stderr12
-rw-r--r--testsuite/tests/ghc-api/annotations/T10358.stdout58
-rw-r--r--testsuite/tests/ghc-api/annotations/Test10358.hs8
-rw-r--r--testsuite/tests/ghc-api/annotations/all.T1
-rw-r--r--testsuite/tests/ghc-api/annotations/boolFormula.stderr17
-rw-r--r--testsuite/tests/ghc-api/annotations/t10358.hs118
8 files changed, 205 insertions, 17 deletions
diff --git a/testsuite/tests/ghc-api/annotations/.gitignore b/testsuite/tests/ghc-api/annotations/.gitignore
index 4f6f3be153..b8bba4fdcc 100644
--- a/testsuite/tests/ghc-api/annotations/.gitignore
+++ b/testsuite/tests/ghc-api/annotations/.gitignore
@@ -5,6 +5,7 @@ exampleTest
listcomps
t10309
t10357
+t10358
t10255
t10268
t10269
diff --git a/testsuite/tests/ghc-api/annotations/Makefile b/testsuite/tests/ghc-api/annotations/Makefile
index 0cebeaf1db..7cf7baf5b7 100644
--- a/testsuite/tests/ghc-api/annotations/Makefile
+++ b/testsuite/tests/ghc-api/annotations/Makefile
@@ -37,6 +37,13 @@ listcomps:
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc listcomps
./listcomps "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
+t10358:
+ rm -f t10358.o t10358.hi
+ '$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10358
+ ./t10358 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
+
+.PHONY: t10358
+
t10255:
rm -f t10255.o t10255.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10255
diff --git a/testsuite/tests/ghc-api/annotations/T10358.stderr b/testsuite/tests/ghc-api/annotations/T10358.stderr
new file mode 100644
index 0000000000..96daaad878
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/T10358.stderr
@@ -0,0 +1,12 @@
+
+Test10358.hs:5:14: error: Not in scope: ‘x’
+
+Test10358.hs:5:16: error: Not in scope: ‘x’
+
+Test10358.hs:6:12: error: Not in scope: ‘v’
+
+Test10358.hs:6:14: error: Not in scope: ‘v’
+
+Test10358.hs:6:16: error: Not in scope: ‘v’
+
+Test10358.hs:7:12: error: Not in scope: ‘d’
diff --git a/testsuite/tests/ghc-api/annotations/T10358.stdout b/testsuite/tests/ghc-api/annotations/T10358.stdout
new file mode 100644
index 0000000000..02dcb7a1c3
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/T10358.stdout
@@ -0,0 +1,58 @@
+---Problems---------------------
+[
+(AK <no location info> AnnEofPos = [Test10358.hs:9:1])
+]
+
+---Problems'--------------------
+[(AnnEofPos, Test10358.hs:9:1)]
+--------------------------------
+[
+(AK Test10358.hs:1:1 AnnModule = [Test10358.hs:2:1-6])
+
+(AK Test10358.hs:1:1 AnnWhere = [Test10358.hs:2:18-22])
+
+(AK Test10358.hs:(4,1)-(8,6) AnnEqual = [Test10358.hs:4:13])
+
+(AK Test10358.hs:(4,1)-(8,6) AnnFunId = [Test10358.hs:4:1-7])
+
+(AK Test10358.hs:(4,1)-(8,6) AnnSemi = [Test10358.hs:9:1])
+
+(AK Test10358.hs:(5,3)-(8,6) AnnIn = [Test10358.hs:8:3-4])
+
+(AK Test10358.hs:(5,3)-(8,6) AnnLet = [Test10358.hs:5:3-5])
+
+(AK Test10358.hs:5:7-10 AnnBang = [Test10358.hs:5:7])
+
+(AK Test10358.hs:5:7-16 AnnEqual = [Test10358.hs:5:12])
+
+(AK Test10358.hs:5:7-16 AnnSemi = [Test10358.hs:5:17])
+
+(AK Test10358.hs:5:14-16 AnnVal = [Test10358.hs:5:15])
+
+(AK Test10358.hs:5:19-22 AnnBang = [Test10358.hs:5:19])
+
+(AK Test10358.hs:5:19-32 AnnEqual = [Test10358.hs:5:24])
+
+(AK Test10358.hs:5:19-32 AnnSemi = [Test10358.hs:6:7])
+
+(AK Test10358.hs:5:26-32 AnnVal = [Test10358.hs:5:29])
+
+(AK Test10358.hs:6:7-16 AnnEqual = [Test10358.hs:6:10])
+
+(AK Test10358.hs:6:7-16 AnnFunId = [Test10358.hs:6:7-8])
+
+(AK Test10358.hs:6:7-16 AnnSemi = [Test10358.hs:7:7])
+
+(AK Test10358.hs:6:12-14 AnnVal = [Test10358.hs:6:13])
+
+(AK Test10358.hs:6:12-16 AnnVal = [Test10358.hs:6:15])
+
+(AK Test10358.hs:7:7-17 AnnEqual = [Test10358.hs:7:10])
+
+(AK Test10358.hs:7:7-17 AnnFunId = [Test10358.hs:7:7-8])
+
+(AK Test10358.hs:7:12-17 AnnVal = [Test10358.hs:7:14])
+
+(AK <no location info> AnnEofPos = [Test10358.hs:9:1])
+]
+
diff --git a/testsuite/tests/ghc-api/annotations/Test10358.hs b/testsuite/tests/ghc-api/annotations/Test10358.hs
new file mode 100644
index 0000000000..9badab2fce
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/Test10358.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE BangPatterns #-}
+module Test10358 where
+
+mtGamma a b =
+ let !x_2 = x*x; !x_4 = x_2*x_2
+ v3 = v*v*v
+ dv = d * v3
+ in 5
diff --git a/testsuite/tests/ghc-api/annotations/all.T b/testsuite/tests/ghc-api/annotations/all.T
index 5614127cf0..b60f0bc622 100644
--- a/testsuite/tests/ghc-api/annotations/all.T
+++ b/testsuite/tests/ghc-api/annotations/all.T
@@ -12,3 +12,4 @@ 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'])
+test('T10358', normal, run_command, ['$MAKE -s --no-print-directory t10358'])
diff --git a/testsuite/tests/ghc-api/annotations/boolFormula.stderr b/testsuite/tests/ghc-api/annotations/boolFormula.stderr
deleted file mode 100644
index 65cbf267af..0000000000
--- a/testsuite/tests/ghc-api/annotations/boolFormula.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-
-TestBoolFormula.hs:3:1: Warning:
- The MINIMAL pragma does not require:
- ‘aOp’, ‘bOp’, ‘cOp’, ‘dOp’, ‘eOp’, and ‘fOp’
- but there is no default implementation.
- In the class declaration for ‘ManyOps’
-
-TestBoolFormula.hs:15:1: Warning:
- The MINIMAL pragma does not require:
- ‘baq’, ‘baz’, and ‘quux’
- but there is no default implementation.
- In the class declaration for ‘Foo’
-
-TestBoolFormula.hs:23:10: Warning:
- No explicit implementation for
- either (‘foo’ and ‘baq’) or ‘foo’
- In the instance declaration for ‘Foo Int’
diff --git a/testsuite/tests/ghc-api/annotations/t10358.hs b/testsuite/tests/ghc-api/annotations/t10358.hs
new file mode 100644
index 0000000000..82994cc27d
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/t10358.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 "Test10358"
+
+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)