- = -- Deal with the method declarations themselves
- processInstBinds
- clas
- (makeClassDeclDefaultMethodRhs clas default_method_ids)
- [] -- No tyvars in scope for "this inst decl"
- emptyLIE -- No insts available
- (map RealId default_method_ids)
- default_binds `thenTc` \ (dicts_needed, default_binds') ->
-
- returnTc (dicts_needed, SingleBind (NonRecBind default_binds'))
+ = newDicts origin [(clas,inst_ty)] `thenNF_Tc` \ (this_dict, [this_dict_id]) ->
+ mapAndUnzipNF_Tc mk_method default_method_ids `thenNF_Tc` \ (insts_s, local_defm_ids) ->
+ let
+ avail_insts = this_dict `plusLIE` unionManyBags insts_s -- Insts available
+ clas_tyvar_set = unitTyVarSet clas_tyvar
+ in
+ tcExtendGlobalTyVars clas_tyvar_set (
+ processInstBinds
+ clas
+ (makeClassDeclDefaultMethodRhs clas local_defm_ids)
+ avail_insts
+ local_defm_ids
+ default_binds
+ ) `thenTc` \ (insts_needed, default_binds') ->
+
+ tcSimplifyAndCheck
+ clas_tyvar_set
+ avail_insts
+ insts_needed `thenTc` \ (const_lie, dict_binds) ->
+
+
+ let
+ defm_binds = AbsBinds
+ [clas_tyvar]
+ [this_dict_id]
+ (local_defm_ids `zip` map RealId default_method_ids)
+ dict_binds
+ (RecBind default_binds')
+ in
+ returnTc (const_lie, defm_binds)
+ where
+ inst_ty = mkTyVarTy clas_tyvar
+ mk_method defm_id = newMethod origin (RealId defm_id) [inst_ty]
+ origin = ClassDeclOrigin