Commit 9d908c52 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Close over kinds when checking fundep coverage (Trac #8391)

See Note [Closing over kinds in coverage] in FunDeps
parent 7e444802
......@@ -466,10 +466,11 @@ checkInstCoverage be_liberal clas theta inst_taus
| if be_liberal then liberal_ok else conservative_ok
= Nothing
| otherwise
= Just msg
= pprTrace "cic" (vcat [ppr clas <+> ppr inst_taus, ppr fd, ppr ls_tvs, ppr rs_tvs, ppr (oclose theta ls_tvs), ppr theta]) $
Just msg
where
(ls,rs) = instFD fd tyvars inst_taus
ls_tvs = tyVarsOfTypes ls
ls_tvs = closeOverKinds (tyVarsOfTypes ls) -- See Note [Closing over kinds in coverage]
rs_tvs = tyVarsOfTypes rs
conservative_ok = rs_tvs `subVarSet` ls_tvs
......@@ -492,6 +493,22 @@ checkInstCoverage be_liberal clas theta inst_taus
ptext (sLit "Using UndecidableInstances might help") ]
\end{code}
Note [Closing over kinds in coverage]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppose we have a fundep (a::k) -> b
Then if 'a' is instantiated to (x y), where x:k2->*, y:k2,
then fixing x really fixes k2 as well, and so k2 should be added to
the lhs tyvars in the fundep check.
Example (Trac #8391), using liberal coverage
type Foo a = a -- Foo :: forall k. k -> k
class Bar a b | a -> b
instance Bar a (Foo a)
In the instance decl, (a:k) does fix (Foo k a), but only if we notice
that (a:k) fixes k.
Note [Coverage condition]
~~~~~~~~~~~~~~~~~~~~~~~~~
Example
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment