summaryrefslogtreecommitdiff
path: root/testsuite/tests/rename/should_compile
diff options
context:
space:
mode:
authorMatthew Yacavone <matthew@yacavone.net>2018-10-27 14:01:42 -0400
committerRichard Eisenberg <rae@cs.brynmawr.edu>2018-10-27 14:54:56 -0400
commit512eeb9bb9a81e915bfab25ca16bc87c62252064 (patch)
tree803e752c6907fdfc89a5f71e6bfda04d7ef86bea /testsuite/tests/rename/should_compile
parent23956b2ada690c78a134fe6d149940c777c7efcc (diff)
downloadhaskell-512eeb9bb9a81e915bfab25ca16bc87c62252064.tar.gz
More explicit foralls (GHC Proposal 0007)
Allow the user to explicitly bind type/kind variables in type and data family instances (including associated instances), closed type family equations, and RULES pragmas. Follows the specification of GHC Proposal 0007, also fixes #2600. Advised by Richard Eisenberg. This modifies the Template Haskell AST -- old code may break! Other Changes: - convert HsRule to a record - make rnHsSigWcType more general - add repMaybe to DsMeta Includes submodule update for Haddock. Test Plan: validate Reviewers: goldfire, bgamari, alanz Subscribers: simonpj, RyanGlScott, goldfire, rwbarton, thomie, mpickering, carter GHC Trac Issues: #2600, #14268 Differential Revision: https://phabricator.haskell.org/D4894
Diffstat (limited to 'testsuite/tests/rename/should_compile')
-rw-r--r--testsuite/tests/rename/should_compile/ExplicitForAllRules1.hs45
-rw-r--r--testsuite/tests/rename/should_compile/ExplicitForAllRules1.stderr4
-rw-r--r--testsuite/tests/rename/should_compile/T2600.hs19
-rw-r--r--testsuite/tests/rename/should_compile/T2600.stderr10
-rw-r--r--testsuite/tests/rename/should_compile/all.T4
5 files changed, 82 insertions, 0 deletions
diff --git a/testsuite/tests/rename/should_compile/ExplicitForAllRules1.hs b/testsuite/tests/rename/should_compile/ExplicitForAllRules1.hs
new file mode 100644
index 0000000000..7862468d17
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/ExplicitForAllRules1.hs
@@ -0,0 +1,45 @@
+{-# LANGUAGE ExplicitForAll #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TypeInType #-}
+{-# LANGUAGE TypeApplications #-}
+
+module ExplicitForAllRules1 where
+
+import Data.Proxy
+import Data.Kind
+
+-- From Proposal 0007 (w/ fix to "example")
+
+{-# RULES
+"example" forall a b. forall. map @a @b f = f
+"example2" forall a. forall (x :: a). id x = x
+ #-}
+
+{-# NOINLINE f #-}
+f :: a -> b
+f = undefined
+
+-- More tests
+
+{-# RULES
+"example3" forall (a :: Type -> Type) (b :: a Int) c. forall x y. g @(Proxy b) @(Proxy c) x y = ()
+"example4" forall (a :: Bool) (b :: Proxy a). forall x. g @(Proxy b) @() x = id @()
+"example5" forall (a :: Type). forall. h @a = id @a
+"example5" forall k (c :: k). forall (x :: Proxy c). id @(Proxy c) x = x
+ #-}
+
+{-# NOINLINE g #-}
+g :: a -> b -> ()
+g _ _ = ()
+
+{-# NOINLINE h #-}
+h :: a -> a
+h x = x
+
+-- Should NOT have a parse error :(
+{-# RULES "example6" forall a forall. g a forall = () #-}
+
+-- Should generate a warning
+{-# RULES "example7" forall a b. forall (x :: a). id x = x #-}
diff --git a/testsuite/tests/rename/should_compile/ExplicitForAllRules1.stderr b/testsuite/tests/rename/should_compile/ExplicitForAllRules1.stderr
new file mode 100644
index 0000000000..54a32adafd
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/ExplicitForAllRules1.stderr
@@ -0,0 +1,4 @@
+
+ExplicitForAllRules1.hs:45:31: warning: [-Wunused-foralls (in -Wextra)]
+ Unused quantified type variable ‘b’
+ in the rule "example7"
diff --git a/testsuite/tests/rename/should_compile/T2600.hs b/testsuite/tests/rename/should_compile/T2600.hs
new file mode 100644
index 0000000000..bdf483cace
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T2600.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE ExplicitForAll #-}
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE TypeApplications #-}
+
+module T2600 where
+
+-- ** See trac #10595 for why we're okay with this generating warnings! **
+
+class T t where
+ to :: [a] -> t a
+ from :: t a -> [a]
+ tmap :: (a -> a) -> t a -> t a
+
+{-# RULES
+
+"myrule" forall t a. forall f x.
+ from (tmap f (to x :: t a)) = map f (from (to x :: t a))
+
+ #-}
diff --git a/testsuite/tests/rename/should_compile/T2600.stderr b/testsuite/tests/rename/should_compile/T2600.stderr
new file mode 100644
index 0000000000..91f594ff9e
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T2600.stderr
@@ -0,0 +1,10 @@
+
+T2600.hs:16:1: warning: [-Winline-rule-shadowing (in -Wdefault)]
+ Rule "myrule" may never fire
+ because rule "Class op tmap" for ‘tmap’ might fire first
+ Probable fix: add phase [n] or [~n] to the competing rule
+
+T2600.hs:16:1: warning: [-Winline-rule-shadowing (in -Wdefault)]
+ Rule "myrule" may never fire
+ because rule "Class op to" for ‘to’ might fire first
+ Probable fix: add phase [n] or [~n] to the competing rule \ No newline at end of file
diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T
index 3a90cbd667..a3f862f8a4 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -81,6 +81,10 @@ test('T2205', normal, compile, [''])
test('T2334', normal, compile, [''])
test('T2506', normal, compile, [''])
+
+test('ExplicitForAllRules1', normal, compile, ['-Wunused-foralls'])
+test('T2600', normal, compile, [''])
+
test('T2914', normal, compile, [''])
test('T3221', normal, compile, [''])
test('T3262', normal, compile, [''])