summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2022-07-21 15:13:58 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-07-22 08:18:46 -0400
commit6379f9429e8f9e8f58f4c3c8206c265620feb26e (patch)
tree152e3dc1801afb3b138283c05eade589018201c2
parenta8b150e7809cbcd216963e0b3942b26722173f57 (diff)
downloadhaskell-6379f9429e8f9e8f58f4c3c8206c265620feb26e.tar.gz
Add test for #21360
The way record updates are typechecked/desugared changed in MR !7981. Because we desugar in the typechecker to a simple case expression, the pattern match checker becomes able to spot the long-distance information and avoid emitting an incorrect pattern match warning. Fixes #21360
-rw-r--r--testsuite/tests/pmcheck/should_compile/T21360.hs22
-rw-r--r--testsuite/tests/pmcheck/should_compile/all.T1
2 files changed, 23 insertions, 0 deletions
diff --git a/testsuite/tests/pmcheck/should_compile/T21360.hs b/testsuite/tests/pmcheck/should_compile/T21360.hs
new file mode 100644
index 0000000000..db517a35a9
--- /dev/null
+++ b/testsuite/tests/pmcheck/should_compile/T21360.hs
@@ -0,0 +1,22 @@
+{-# OPTIONS_GHC -Wincomplete-record-updates #-}
+
+module T21360 where
+
+data Foo = A {a :: Int} | B deriving Show
+
+foo = A 4
+
+-- wibble is safe - no warning
+wibble = do
+ case foo of
+ bar@A{} -> Just bar{a = 9}
+ _ -> fail ":("
+
+-- using guards doesn't throw a warning
+twomble | bar@A{} <- foo = Just bar{a = 9}
+ | otherwise = fail ":("
+
+-- sworble has the same semantics as wibble and twomble - but we get a warning!
+sworble = do
+ bar@A{} <- Just foo
+ Just bar{a = 9}
diff --git a/testsuite/tests/pmcheck/should_compile/all.T b/testsuite/tests/pmcheck/should_compile/all.T
index 1af8c91441..fe63d364f7 100644
--- a/testsuite/tests/pmcheck/should_compile/all.T
+++ b/testsuite/tests/pmcheck/should_compile/all.T
@@ -89,6 +89,7 @@ test('T19384', expect_broken(19384), compile, [overlapping_incomplete])
test('T19622', normal, compile, [overlapping_incomplete])
test('T20631', normal, compile, [overlapping_incomplete])
test('T20642', normal, compile, [overlapping_incomplete])
+test('T21360', normal, compile, [overlapping_incomplete])
# Other tests
test('pmc001', [], compile, [overlapping_incomplete])