Be more relaxed about reporting ambiguous class methods
[ghc-hetmet.git] / compiler / typecheck / TcTyClsDecls.lhs
index 8ab053e..834bedc 100644 (file)
@@ -24,6 +24,7 @@ import TcClassDcl
 import TcHsType
 import TcMType
 import TcType
+import FunDeps
 import Type
 import Generics
 import Class
@@ -1043,8 +1044,13 @@ checkValidClass cls
        ; checkValidType (FunSigCtxt op_name) tau
 
                -- Check that the type mentions at least one of
-               -- the class type variables
-       ; checkTc (any (`elemVarSet` tyVarsOfType tau) tyvars)
+               -- the class type variables...or at least one reachable
+               -- from one of the class variables.  Example: tc223
+               --   class Error e => Game b mv e | b -> mv e where
+               --      newBoard :: MonadState b m => m ()
+               -- Here, MonadState has a fundep m->b, so newBoard is fine
+       ; let grown_tyvars = grow theta (mkVarSet tyvars)
+       ; checkTc (tyVarsOfType tau `intersectsVarSet` grown_tyvars)
                  (noClassTyVarErr cls sel_id)
 
                -- Check that for a generic method, the type of 
@@ -1150,7 +1156,7 @@ newtypeFieldErr con_name n_flds
 badSigTyDecl tc_name
   = vcat [ ptext SLIT("Illegal kind signature") <+>
           quotes (ppr tc_name)
-        , nest 2 (parens $ ptext SLIT("Use -fglasgow-exts to allow indexed types")) ]
+        , nest 2 (parens $ ptext SLIT("Use -findexed-types to allow indexed types")) ]
 
 badKindSigCtxt tc_name
   = vcat [ ptext SLIT("Illegal context in kind signature") <+>
@@ -1160,7 +1166,7 @@ badKindSigCtxt tc_name
 badIdxTyDecl tc_name
   = vcat [ ptext SLIT("Illegal indexed type instance for") <+>
           quotes (ppr tc_name)
-        , nest 2 (parens $ ptext SLIT("Use -fglasgow-exts to allow indexed types")) ]
+        , nest 2 (parens $ ptext SLIT("Use -findexed-types to allow indexed types")) ]
 
 badGadtIdxTyDecl tc_name
   = vcat [ ptext SLIT("Illegal generalised algebraic data declaration for") <+>