Fix #15385 by using addDictsDs in matchGuards
authorRyan Scott <ryan.gl.scott@gmail.com>
Mon, 30 Jul 2018 12:47:39 +0000 (08:47 -0400)
committerRyan Scott <ryan.gl.scott@gmail.com>
Mon, 30 Jul 2018 12:47:39 +0000 (08:47 -0400)
commit9d388eb83e797fd28e14868009c4786f3f1a8aa6
tree6f0bcc4637c6b9cb565f093b43c88dede3e29acb
parent11de4380c2f16f374c6e8fbacf8dce00376e7efb
Fix #15385 by using addDictsDs in matchGuards

Summary:
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
compiler/deSugar/Check.hs
compiler/deSugar/DsGRHSs.hs
compiler/deSugar/DsUtils.hs
compiler/deSugar/Match.hs-boot
compiler/hsSyn/HsPat.hs
testsuite/tests/pmcheck/should_compile/T15385.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/all.T