Commit 2d06a9f1 authored by Simon Peyton Jones's avatar Simon Peyton Jones

Improve error message for fundeps

Improve error message fundeps, especially when PolyKinds means that
the un-determined variables are (invisible) kind variables.

See Trac #10570.
parent 888026db
...@@ -377,19 +377,22 @@ checkInstCoverage be_liberal clas theta inst_taus ...@@ -377,19 +377,22 @@ checkInstCoverage be_liberal clas theta inst_taus
where where
(tyvars, fds) = classTvsFds clas (tyvars, fds) = classTvsFds clas
fundep_ok fd fundep_ok fd
| if be_liberal then liberal_ok else conservative_ok | isEmptyVarSet undetermined_tvs = IsValid
= IsValid | otherwise = NotValid msg
| otherwise
= NotValid msg
where where
(ls,rs) = instFD fd tyvars inst_taus (ls,rs) = instFD fd tyvars inst_taus
ls_tvs = tyVarsOfTypes ls ls_tvs = tyVarsOfTypes ls
rs_tvs = tyVarsOfTypes rs rs_tvs = tyVarsOfTypes rs
conservative_ok = rs_tvs `subVarSet` closeOverKinds ls_tvs undetermined_tvs | be_liberal = liberal_undet_tvs
liberal_ok = rs_tvs `subVarSet` oclose theta (closeOverKinds ls_tvs) | otherwise = conserv_undet_tvs
liberal_undet_tvs = rs_tvs `minusVarSet`oclose theta (closeOverKinds ls_tvs)
conserv_undet_tvs = rs_tvs `minusVarSet` closeOverKinds ls_tvs
-- closeOverKinds: see Note [Closing over kinds in coverage] -- closeOverKinds: see Note [Closing over kinds in coverage]
undet_list = varSetElemsKvsFirst undetermined_tvs
msg = vcat [ -- text "ls_tvs" <+> ppr ls_tvs msg = vcat [ -- text "ls_tvs" <+> ppr ls_tvs
-- , text "closed ls_tvs" <+> ppr (closeOverKinds ls_tvs) -- , text "closed ls_tvs" <+> ppr (closeOverKinds ls_tvs)
-- , text "theta" <+> ppr theta -- , text "theta" <+> ppr theta
...@@ -408,7 +411,11 @@ checkInstCoverage be_liberal clas theta inst_taus ...@@ -408,7 +411,11 @@ checkInstCoverage be_liberal clas theta inst_taus
else ptext (sLit "do not jointly")) else ptext (sLit "do not jointly"))
<+> ptext (sLit "determine rhs type")<>plural rs <+> ptext (sLit "determine rhs type")<>plural rs
<+> pprQuotedList rs ] <+> pprQuotedList rs ]
, ppWhen (not be_liberal && liberal_ok) $ , ptext (sLit "Un-determined variable") <> plural undet_list <> colon
<+> pprWithCommas ppr undet_list
, ppWhen (all isKindVar undet_list) $
ptext (sLit "(Use -fprint-explicit-kinds to see the kind variables in the types)")
, ppWhen (not be_liberal && isEmptyVarSet liberal_undet_tvs) $
ptext (sLit "Using UndecidableInstances might help") ] ptext (sLit "Using UndecidableInstances might help") ]
{- Note [Closing over kinds in coverage] {- Note [Closing over kinds in coverage]
......
{-# LANGUAGE FunctionalDependencies, PolyKinds, FlexibleInstances #-}
module T10570 where
import Data.Proxy
class ConsByIdx2 x a m cls | x -> m where
consByIdx2 :: x -> a -> m cls
instance ConsByIdx2 Int a Proxy cls where
consByIdx2 _ _ = Proxy
T10570.hs:10:10: error:
Illegal instance declaration for ‘ConsByIdx2 Int a Proxy cls’
The coverage condition fails in class ‘ConsByIdx2’
for functional dependency: ‘x -> m’
Reason: lhs type ‘Int’ does not determine rhs type ‘Proxy’
Un-determined variable: k
(Use -fprint-explicit-kinds to see the kind variables in the types)
In the instance declaration for ‘ConsByIdx2 Int a Proxy cls’
T9106.hs:13:10: T9106.hs:13:10: error:
Illegal instance declaration for ‘FunctorN n f a (f fa)’ Illegal instance declaration for ‘FunctorN n f a (f fa)’
The liberal coverage condition fails in class ‘FunctorN’ The liberal coverage condition fails in class ‘FunctorN’
for functional dependency: ‘n f a -> fa’ for functional dependency: ‘n f a -> fa’
Reason: lhs types ‘n’, ‘f’, ‘a’ Reason: lhs types ‘n’, ‘f’, ‘a’
do not jointly determine rhs type ‘f fa’ do not jointly determine rhs type ‘f fa’
Un-determined variable: fa
In the instance declaration for ‘FunctorN n f a (f fa)’ In the instance declaration for ‘FunctorN n f a (f fa)’
...@@ -118,3 +118,4 @@ test('T10041', normal, compile, ['']) ...@@ -118,3 +118,4 @@ test('T10041', normal, compile, [''])
test('T10451', normal, compile_fail, ['']) test('T10451', normal, compile_fail, [''])
test('T10516', normal, compile_fail, ['']) test('T10516', normal, compile_fail, [''])
test('T10503', normal, compile_fail, ['']) test('T10503', normal, compile_fail, [''])
test('T10570', normal, compile_fail, [''])
T2247.hs:6:10: T2247.hs:6:10: error:
Illegal instance declaration for ‘FD a b’ Illegal instance declaration for ‘FD a b’
The liberal coverage condition fails in class ‘FD’ The liberal coverage condition fails in class ‘FD’
for functional dependency: ‘a -> b’ for functional dependency: ‘a -> b’
Reason: lhs type ‘a’ does not determine rhs type ‘b’ Reason: lhs type ‘a’ does not determine rhs type ‘b’
Un-determined variable: b
In the instance declaration for ‘FD a b’ In the instance declaration for ‘FD a b’
tcfail170.hs:7:10: tcfail170.hs:7:10: error:
Illegal instance declaration for ‘C [p] [q]’ Illegal instance declaration for ‘C [p] [q]’
The coverage condition fails in class ‘C’ The coverage condition fails in class ‘C’
for functional dependency: ‘a -> b’ for functional dependency: ‘a -> b’
Reason: lhs type ‘[p]’ does not determine rhs type ‘[q]’ Reason: lhs type ‘[p]’ does not determine rhs type ‘[q]’
Un-determined variable: q
In the instance declaration for ‘C [p] [q]’ In the instance declaration for ‘C [p] [q]’
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