From e649085bb35628e10b08a9a1ef27095ad0510b40 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Mon, 30 Jul 2018 08:47:39 -0400 Subject: Fix #15385 by using addDictsDs in matchGuards When coverage checking pattern-matches, we rely on the call sites in the desugarer to populate the local dictionaries and term evidence in scope using `addDictsDs` and `addTmCsDs`. But it turns out that only the call site for desugaring `case` expressions was actually doing this properly. In another part of the desugarer, `matchGuards` (which handles pattern guards), it did not update the local dictionaries in scope at all, leading to #15385. Fixing this is relatively straightforward: just augment the `BindStmt` case of `matchGuards` to use `addDictsDs` and `addTmCsDs`. Accomplishing this took a little bit of import/export tweaking: * We now need to export `collectEvVarsPat` from `HsPat.hs`. * To avoid an import cycle with `Check.hs`, I moved `isTrueLHsExpr` from `DsGRHSs.hs` to `DsUtils.hs`, which resides lower on the import chain. Test Plan: make test TEST=T15385 Reviewers: simonpj, bgamari Reviewed By: simonpj Subscribers: rwbarton, thomie, carter GHC Trac Issues: #15385 Differential Revision: https://phabricator.haskell.org/D4968 (cherry picked from commit 9d388eb83e797fd28e14868009c4786f3f1a8aa6) --- testsuite/tests/pmcheck/should_compile/T15385.hs | 21 +++++++++++++++++++++ testsuite/tests/pmcheck/should_compile/all.T | 2 ++ 2 files changed, 23 insertions(+) create mode 100644 testsuite/tests/pmcheck/should_compile/T15385.hs (limited to 'testsuite') diff --git a/testsuite/tests/pmcheck/should_compile/T15385.hs b/testsuite/tests/pmcheck/should_compile/T15385.hs new file mode 100644 index 0000000000..dedf6c1553 --- /dev/null +++ b/testsuite/tests/pmcheck/should_compile/T15385.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE GADTs #-} +{-# LANGUAGE MultiWayIf #-} +{-# LANGUAGE TypeOperators #-} +{-# OPTIONS_GHC -Wincomplete-patterns #-} +module T15385 where + +import Data.Type.Equality + +data T a where + TInt :: T Int + TBool :: T Bool + +f1, f2 :: a :~: Int -> T a -> () +f1 eq t + | Refl <- eq + = case t of + TInt -> () +f2 eq t + = if | Refl <- eq + -> case t of + TInt -> () diff --git a/testsuite/tests/pmcheck/should_compile/all.T b/testsuite/tests/pmcheck/should_compile/all.T index a7b8bfb04c..4ee354ddb2 100644 --- a/testsuite/tests/pmcheck/should_compile/all.T +++ b/testsuite/tests/pmcheck/should_compile/all.T @@ -49,6 +49,8 @@ test('T14098', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) test('T15450', normal, compile, ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) +test('T15385', normal, compile, + ['-fwarn-incomplete-patterns -fwarn-overlapping-patterns']) # Other tests test('pmc001', [], compile, -- cgit v1.2.1