[project @ 2004-03-11 10:52:55 by simonpj]
authorsimonpj <unknown>
Thu, 11 Mar 2004 10:52:55 +0000 (10:52 +0000)
committersimonpj <unknown>
Thu, 11 Mar 2004 10:52:55 +0000 (10:52 +0000)
Fix a long-standing bug; the type checker should recover from a failure
in the default method of a class declaration, else the default method
doesn't get added to the type envt, and we get an opaque
    tcLookupGlobal: `FunnyError.$dmb' is not in scope
message.

ghc/compiler/typecheck/TcClassDcl.lhs

index 9ae343b..ee506bc 100644 (file)
@@ -336,7 +336,13 @@ tcMethodBind
 
 tcMethodBind xtve inst_tyvars inst_theta avail_insts prags
             (sel_id, meth_id, meth_bind)
-  =    -- Check the bindings; first adding inst_tyvars to the envt
+  = recoverM (returnM emptyBag) $
+       -- If anything fails, recover returning no bindings.
+       -- This is particularly useful when checking the default-method binding of
+       -- a class decl. If we don't recover, we don't add the default method to
+       -- the type enviroment, and we get a tcLookup failure on $dmeth later.
+
+       -- Check the bindings; first adding inst_tyvars to the envt
        -- so that we don't quantify over them in nested places
      mkTcSig meth_id                           `thenM` \ meth_sig ->