[GHC] #12949: Pattern coverage checker ignores dictionary arguments
GHC
ghc-devs at haskell.org
Fri Apr 6 08:02:57 UTC 2018
#12949: Pattern coverage checker ignores dictionary arguments
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: gkaracha
Type: bug | Status: new
Priority: normal | Milestone: 8.6.1
Component: Compiler | Version: 8.0.1
Resolution: | Keywords:
| PatternMatchWarnings
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
error/warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by sighingnow):
Hello,
I'm working on this ticket and now I can tell what's going wrong with the
case in comment:11. I think I need some help to go further and submit the
patch.
Look at the example in comment:11:
{{{#!hs
q :: forall a b . (Foo a, Foo b) => Result a b
q = case foo :: Maybe a of
Nothing -> case foo :: Maybe b of
Nothing -> Neither
Just c -> That c
}}}
When do `checkMatches` on inner `case` statement, we first call
`mkInitialUncovered` to set up a NameEnv, in this function we use
`getTmCsDs` to obtain the initial name env, we have
{{{#!hs
[(ds_d14i, foo), (ds_d14h, Nothing), (ds_d14h, foo)]
}}}
Nothing that these two `foo` have different `Id` (type), but the same
`Name`. We then translate them as `ComplexEq`, only keeping the `Name` in
`PmExprVar`. Then we get the `initTmState`.
In `ConVar` case of `pmcheckHd`, we have ComplexEq `(ds_d14i, Just
$pm_d14m)` and use `solveOneEq` to decide whether it is a valid candidate
`PmCon`. In `solveOneEq`, we first do deep substitution by looking up the
`Name` of `PmExprVar` from env. Now `ds_d14i` is replaced with `foo` and
further replaced with `Nothing`, then `solveOneEq` fails and the `Just`
pattern is redundant.
---------------------------------------------
To solve this, we need to consider both name and type of variables when do
substitution. In comment:7 gkaracha proposed that
> Turning Name back into Id in the checker
Should we move from `PmExprVar Name` to `PmExprVar Id` ? In
`varDeepLookup`, when find the `PmExpr` from PrVarEnv, we could first
check it's type then do further substitution. Do that make sense ?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12949#comment:16>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list