#include "HsVersions.h"
-import RnHsSyn ( RenamedMonoBinds, RenamedSig(..) )
+import RnHsSyn ( RenamedMonoBinds, RenamedSig )
+import CmdLineOpts ( opt_AllowOverlappingInstances )
import TcMonad
import Inst ( InstanceMapper )
import Bag ( bagToList, Bag )
import Class ( ClassInstEnv, Class, classBigSig )
-import Id ( mkDictFunId, Id )
+import MkId ( mkDictFunId )
+import Id ( Id )
import SpecEnv ( emptySpecEnv, addToSpecEnv )
import Maybes ( MaybeErr(..), mkLookupFunDef )
import Name ( getSrcLoc, Name )
import Unique ( Unique )
import Util ( equivClasses, panic, assertPanic )
import Outputable
+import List ( nub )
\end{code}
instance c => k (t tvs) where b
sc_theta' = instantiateThetaTy (zipTyVarEnv class_tyvars inst_tys) sc_theta
dfun_theta = case inst_decl_theta of
- [] -> [] -- If inst_decl_theta is empty, then we don't
+ [] -> [] -- If inst_decl_theta is empty, then we don't
-- want to have any dict arguments, so that we can
-- expose the constant methods.
- other -> inst_decl_theta ++ sc_theta'
- -- Otherwise we pass the superclass dictionaries to
- -- the dictionary function; the Mark Jones optimisation.
+ other -> nub (inst_decl_theta ++ sc_theta')
+ -- Otherwise we pass the superclass dictionaries to
+ -- the dictionary function; the Mark Jones optimisation.
+ --
+ -- NOTE the "nub". I got caught by this one:
+ -- class Monad m => MonadT t m where ...
+ -- instance Monad m => MonadT (EnvT env) m where ...
+ -- Here, the inst_decl_theta has (Monad m); but so
+ -- does the sc_theta'!
dfun_ty = mkSigmaTy inst_tyvars dfun_theta (mkDictTy clas inst_tys)
dfun_id _ src_loc _)
class_inst_env
= -- Add the instance to the class's instance environment
- case addToSpecEnv class_inst_env inst_tys dfun_id of
+ case addToSpecEnv opt_AllowOverlappingInstances
+ class_inst_env inst_tyvars inst_tys dfun_id of
Failed (ty', dfun_id') -> addErrTc (dupInstErr clas (inst_tys, src_loc)
(ty', getSrcLoc dfun_id'))
`thenNF_Tc_`