From 6379f9429e8f9e8f58f4c3c8206c265620feb26e Mon Sep 17 00:00:00 2001 From: sheaf Date: Thu, 21 Jul 2022 15:13:58 +0200 Subject: 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 --- testsuite/tests/pmcheck/should_compile/T21360.hs | 22 ++++++++++++++++++++++ testsuite/tests/pmcheck/should_compile/all.T | 1 + 2 files changed, 23 insertions(+) create mode 100644 testsuite/tests/pmcheck/should_compile/T21360.hs 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]) -- cgit v1.2.1