Commit 66bddbb2 authored by Simon Peyton Jones's avatar Simon Peyton Jones

Check that an associated type mentions at least one type variable from the class

Fixes Trac #9167
parent c0258176
......@@ -1620,7 +1620,7 @@ checkValidClass cls
-- since there is no possible ambiguity
; let grown_tyvars = growThetaTyVars theta (mkVarSet tyvars)
; checkTc (arity == 0 || tyVarsOfType tau `intersectsVarSet` grown_tyvars)
(noClassTyVarErr cls sel_id)
(noClassTyVarErr cls (ptext (sLit "class method") <+> quotes (ppr sel_id)))
; case dm of
GenDefMeth dm_name -> do { dm_id <- tcLookupId dm_name
......@@ -1643,8 +1643,12 @@ checkValidClass cls
-- type variable. What a mess!
check_at_defs (fam_tc, defs)
= tcAddDefaultAssocDeclCtxt (tyConName fam_tc) $
mapM_ (checkValidTyFamInst mb_clsinfo fam_tc) defs
= do { traceTc "check-at" (ppr fam_tc $$ ppr (tyConTyVars fam_tc) $$ ppr tyvars)
; checkTc (any (`elem` tyvars) (tyConTyVars fam_tc))
(noClassTyVarErr cls (ptext (sLit "associated type") <+> quotes (ppr fam_tc)))
; tcAddDefaultAssocDeclCtxt (tyConName fam_tc) $
mapM_ (checkValidTyFamInst mb_clsinfo fam_tc) defs }
mb_clsinfo = Just (cls, mkVarEnv [ (tv, mkTyVarTy tv) | tv <- tyvars ])
......@@ -2067,11 +2071,11 @@ classFunDepsErr cls
= vcat [ptext (sLit "Fundeps in class") <+> quotes (ppr cls),
parens (ptext (sLit "Use FunctionalDependencies to allow fundeps"))]
noClassTyVarErr :: Class -> Var -> SDoc
noClassTyVarErr clas op
= sep [ptext (sLit "The class method") <+> quotes (ppr op),
noClassTyVarErr :: Class -> SDoc -> SDoc
noClassTyVarErr clas what
= sep [ptext (sLit "The") <+> what,
ptext (sLit "mentions none of the type variables of the class") <+>
ppr clas <+> hsep (map ppr (classTyVars clas))]
quotes (ppr clas <+> hsep (map ppr (classTyVars clas)))]
recSynErr :: [LTyClDecl Name] -> TcRn ()
recSynErr syn_decls
......
T2888.hs:6:1:
The associated type ‘D’
mentions none of the type variables of the class ‘C w’
In the class declaration for ‘C’
{-# LANGUAGE TypeFamilies #-}
module T9167 where
class C a where
type F b
T9167.hs:5:1:
The associated type ‘F’
mentions none of the type variables of the class ‘C a’
In the class declaration for ‘C’
......@@ -47,7 +47,7 @@ test('T2157', normal, compile_fail, [''])
test('T2203a', normal, compile_fail, [''])
test('T2627b', normal, compile_fail, [''])
test('T2693', normal, compile_fail, [''])
test('T2888', normal, compile, [''])
test('T2888', normal, compile_fail, [''])
test('T3092', normal, compile_fail, [''])
test('NoMatchErr', normal, compile_fail, [''])
test('T2677', normal, compile_fail, [''])
......@@ -120,4 +120,5 @@ test('T8368', normal, compile_fail, [''])
test('T8368a', normal, compile_fail, [''])
test('T8518', normal, compile_fail, [''])
test('T9036', normal, compile_fail, [''])
test('T9167', normal, compile_fail, [''])
tcfail116.hs:5:1:
The class method ‘bug’
mentions none of the type variables of the class Foo a
mentions none of the type variables of the class ‘Foo a’
When checking the class method: bug :: ()
In the class declaration for ‘Foo’
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