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)
committerBen Gamari <ben@smart-cactus.org>
Thu, 2 Aug 2018 00:55:32 +0000 (20:55 -0400)
commite649085bb35628e10b08a9a1ef27095ad0510b40
tree7d1f5492f4dd8fd35b068188e6d19f54e3955286
parent42c51e2f39ce829fa4a380b604c9a7f5ea71d28d
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)
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