summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorKrzysztof Gogolewski <krzysztof.gogolewski@tweag.io>2021-11-21 22:32:29 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-23 01:08:05 -0500
commit3ab3631f41efe9a1ae32a5b1f709152228edb09a (patch)
treecdda5ddc1c2dc146512b98b56c76a9535e9bc021 /testsuite
parent1ed2aa90da7973283408a8a121103d596b05f81b (diff)
downloadhaskell-3ab3631f41efe9a1ae32a5b1f709152228edb09a.tar.gz
Add a warning for GADT match + NoMonoLocalBinds (#20485)
Previously, it was an error to pattern match on a GADT without GADTs or TypeFamilies. This is now allowed. Instead, we check the flag MonoLocalBinds; if it is not enabled, we issue a warning, controlled by -Wgadt-mono-local-binds. Also fixes #20485: pattern synonyms are now checked too.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/gadt/T20485.hs12
-rw-r--r--testsuite/tests/gadt/T20485.stderr15
-rw-r--r--testsuite/tests/gadt/T20485a.hs12
-rw-r--r--testsuite/tests/gadt/all.T2
-rw-r--r--testsuite/tests/patsyn/should_compile/T10997.hs1
-rw-r--r--testsuite/tests/typecheck/should_run/Typeable1.hs2
6 files changed, 43 insertions, 1 deletions
diff --git a/testsuite/tests/gadt/T20485.hs b/testsuite/tests/gadt/T20485.hs
new file mode 100644
index 0000000000..5fb115df6e
--- /dev/null
+++ b/testsuite/tests/gadt/T20485.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE PatternSynonyms #-}
+module T20485 where
+
+import Data.Type.Equality
+
+f :: a :~: b -> a -> b
+f Refl x = x
+
+pattern ReflPat = Refl
+
+g :: a :~: b -> a -> b
+g ReflPat x = x
diff --git a/testsuite/tests/gadt/T20485.stderr b/testsuite/tests/gadt/T20485.stderr
new file mode 100644
index 0000000000..e140b58ad3
--- /dev/null
+++ b/testsuite/tests/gadt/T20485.stderr
@@ -0,0 +1,15 @@
+
+T20485.hs:7:3: warning: [-Wgadt-mono-local-binds (in -Wdefault)]
+ Pattern matching on GADTs without MonoLocalBinds is fragile.
+ Suggested fix:
+ Enable any of the following extensions: GADTs, TypeFamilies
+
+T20485.hs:9:19: warning: [-Wgadt-mono-local-binds (in -Wdefault)]
+ Pattern matching on GADTs without MonoLocalBinds is fragile.
+ Suggested fix:
+ Enable any of the following extensions: GADTs, TypeFamilies
+
+T20485.hs:12:3: warning: [-Wgadt-mono-local-binds (in -Wdefault)]
+ Pattern matching on GADTs without MonoLocalBinds is fragile.
+ Suggested fix:
+ Enable any of the following extensions: GADTs, TypeFamilies
diff --git a/testsuite/tests/gadt/T20485a.hs b/testsuite/tests/gadt/T20485a.hs
new file mode 100644
index 0000000000..fa8c1ee969
--- /dev/null
+++ b/testsuite/tests/gadt/T20485a.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE PatternSynonyms, MonoLocalBinds #-}
+module T20485a where
+
+import Data.Type.Equality
+
+f :: a :~: b -> a -> b
+f Refl x = x
+
+pattern ReflPat = Refl
+
+g :: a :~: b -> a -> b
+g ReflPat x = x
diff --git a/testsuite/tests/gadt/all.T b/testsuite/tests/gadt/all.T
index 9179a40288..3152f3561b 100644
--- a/testsuite/tests/gadt/all.T
+++ b/testsuite/tests/gadt/all.T
@@ -122,3 +122,5 @@ test('T16427', normal, compile_fail, [''])
test('T18191', normal, compile_fail, [''])
test('T20278', normal, compile, [''])
test('SynDataRec', normal, compile, [''])
+test('T20485', normal, compile, [''])
+test('T20485a', normal, compile, [''])
diff --git a/testsuite/tests/patsyn/should_compile/T10997.hs b/testsuite/tests/patsyn/should_compile/T10997.hs
index 69a7940a5f..49278a2a33 100644
--- a/testsuite/tests/patsyn/should_compile/T10997.hs
+++ b/testsuite/tests/patsyn/should_compile/T10997.hs
@@ -1,3 +1,4 @@
+{-# OPTIONS_GHC -Wno-gadt-mono-local-binds #-}
module T10997 where
import T10997a
diff --git a/testsuite/tests/typecheck/should_run/Typeable1.hs b/testsuite/tests/typecheck/should_run/Typeable1.hs
index 02a7ebb98b..9a38c85927 100644
--- a/testsuite/tests/typecheck/should_run/Typeable1.hs
+++ b/testsuite/tests/typecheck/should_run/Typeable1.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE PolyKinds, GADTs #-}
import Type.Reflection
import Data.Kind