summaryrefslogtreecommitdiff
path: root/testsuite/tests/parser
diff options
context:
space:
mode:
authorZubin Duggal <zubin.duggal@gmail.com>2021-11-19 14:21:58 +0530
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-04-06 13:02:04 -0400
commitbabb47d263e0df0fa4e16da6bf86164a2a3e07ea (patch)
tree63f9ea3a73ca093e10d14e8a368d6adfadc0f895 /testsuite/tests/parser
parentd2ae0a3a1a8e31e5d769f1aea95e85793043cb3a (diff)
downloadhaskell-babb47d263e0df0fa4e16da6bf86164a2a3e07ea.tar.gz
Add warnings for file header pragmas that appear in the body of a module (#20385)
Once we are done parsing the header of a module to obtain the options, we look through the rest of the tokens in order to determine if they contain any misplaced file header pragmas that would usually be ignored, potentially resulting in bad error messages. The warnings are reported immediately so that later errors don't shadow over potentially helpful warnings. Metric Increase: T13719
Diffstat (limited to 'testsuite/tests/parser')
-rw-r--r--testsuite/tests/parser/should_compile/T20385.hs7
-rw-r--r--testsuite/tests/parser/should_compile/T20385S.hs8
-rw-r--r--testsuite/tests/parser/should_compile/all.T2
-rw-r--r--testsuite/tests/parser/should_fail/T20385A.hs10
-rw-r--r--testsuite/tests/parser/should_fail/T20385A.stderr12
-rw-r--r--testsuite/tests/parser/should_fail/T20385B.hs11
-rw-r--r--testsuite/tests/parser/should_fail/T20385B.stderr12
-rw-r--r--testsuite/tests/parser/should_fail/all.T2
8 files changed, 64 insertions, 0 deletions
diff --git a/testsuite/tests/parser/should_compile/T20385.hs b/testsuite/tests/parser/should_compile/T20385.hs
new file mode 100644
index 0000000000..c51748d5df
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T20385.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE RecursiveDo #-}
+
+main = pure ()
+
+foo :: forall a. a -> a
+foo x = mdo x
diff --git a/testsuite/tests/parser/should_compile/T20385S.hs b/testsuite/tests/parser/should_compile/T20385S.hs
new file mode 100644
index 0000000000..e9f62260eb
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T20385S.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE RecursiveDo #-}
+module Main where
+
+main = pure ()
+
+foo :: forall a. a -> a
+foo x = mdo (x :: a)
diff --git a/testsuite/tests/parser/should_compile/all.T b/testsuite/tests/parser/should_compile/all.T
index 5412557d10..9a539ddb98 100644
--- a/testsuite/tests/parser/should_compile/all.T
+++ b/testsuite/tests/parser/should_compile/all.T
@@ -185,3 +185,5 @@ test('T20846', normal, compile, ['-dsuppress-uniques -ddump-parsed-ast'])
test('T20551', normal, compile, [''])
test('OpaqueParseWarn1', normal, compile, [''])
+test('T20385', normal, compile, [''])
+test('T20385S', normal, compile, [''])
diff --git a/testsuite/tests/parser/should_fail/T20385A.hs b/testsuite/tests/parser/should_fail/T20385A.hs
new file mode 100644
index 0000000000..6f657591b1
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T20385A.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+import Prelude
+
+{-# LANGUAGE RecursiveDo #-}
+
+main = pure ()
+
+foo :: forall a. a -> a
+foo x = mdo x
diff --git a/testsuite/tests/parser/should_fail/T20385A.stderr b/testsuite/tests/parser/should_fail/T20385A.stderr
new file mode 100644
index 0000000000..5a0bbc14e4
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T20385A.stderr
@@ -0,0 +1,12 @@
+
+T20385A.hs:5:1: warning: [-Wmisplaced-pragmas (in -Wdefault)]
+ Misplaced LANGUAGE pragma
+ Suggested fix:
+ Perhaps you meant to place it in the module header?
+ The module header is the section at the top of the file, before the ‘module’ keyword
+
+T20385A.hs:10:9: error:
+ Variable not in scope: mdo :: a -> a
+ Suggested fixes:
+ • Perhaps use ‘mod’ (imported from Prelude)
+ • Perhaps you intended to use RecursiveDo
diff --git a/testsuite/tests/parser/should_fail/T20385B.hs b/testsuite/tests/parser/should_fail/T20385B.hs
new file mode 100644
index 0000000000..80044ec505
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T20385B.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+module Main where
+
+import Prelude
+
+{-# LANGUAGE RecursiveDo #-}
+
+main = pure ()
+
+foo :: forall a. a -> a
+foo x = mdo x
diff --git a/testsuite/tests/parser/should_fail/T20385B.stderr b/testsuite/tests/parser/should_fail/T20385B.stderr
new file mode 100644
index 0000000000..f854e2be1a
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T20385B.stderr
@@ -0,0 +1,12 @@
+
+T20385B.hs:6:1: warning: [-Wmisplaced-pragmas (in -Wdefault)]
+ Misplaced LANGUAGE pragma
+ Suggested fix:
+ Perhaps you meant to place it in the module header?
+ The module header is the section at the top of the file, before the ‘module’ keyword
+
+T20385B.hs:11:9: error:
+ Variable not in scope: mdo :: a -> a
+ Suggested fixes:
+ • Perhaps use ‘mod’ (imported from Prelude)
+ • Perhaps you intended to use RecursiveDo
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index 1d90ab407e..253d9bcff2 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -205,3 +205,5 @@ test('OpaqueParseFail1', normal, compile_fail, [''])
test('OpaqueParseFail2', normal, compile_fail, [''])
test('OpaqueParseFail3', normal, compile_fail, [''])
test('OpaqueParseFail4', normal, compile_fail, [''])
+test('T20385A', normal, compile_fail, [''])
+test('T20385B', normal, compile_fail, [''])