Be more relaxed about reporting ambiguous class methods
authorsimonpj@microsoft.com <unknown>
Wed, 3 Jan 2007 16:07:03 +0000 (16:07 +0000)
committersimonpj@microsoft.com <unknown>
Wed, 3 Jan 2007 16:07:03 +0000 (16:07 +0000)
(MERGE to STABLE branch, pls)

This patch makes us a bit more relaxed about ambiguous
class method types.  See tc223 for an example.

Reported by Yitzchak Gale

compiler/typecheck/TcTyClsDecls.lhs

index 5574b76..834bedc 100644 (file)
@@ -24,6 +24,7 @@ import TcClassDcl
 import TcHsType
 import TcMType
 import TcType
 import TcHsType
 import TcMType
 import TcType
+import FunDeps
 import Type
 import Generics
 import Class
 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
        ; 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 
                  (noClassTyVarErr cls sel_id)
 
                -- Check that for a generic method, the type of