From: fennecdjay Date: Wed, 4 Sep 2019 19:05:18 +0000 (+0200) Subject: :bug: Fix member overload with different return type X-Git-Tag: nightly~2234 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=209994bc0dbb8c7bec303afd538b8e072c34a3d9;p=gwion.git :bug: Fix member overload with different return type --- diff --git a/src/emit/emit.c b/src/emit/emit.c index f9002f02..c6a0180a 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1644,17 +1644,18 @@ ANN static m_bool emit_exp_dot_special(const Emitter emit, const Exp_Dot* member return emit_vararg(emit, member); } -ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member, const Func func) { +ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member) { + const Func f = exp_self(member)->type->e->d.func; if(isa(member->t_base, t_class) > 0 || GET_FLAG(member->base->type, force)) { - const Instr func_i = emit_add_instr(emit, func->code ? RegPushImm : PushStaticCode); - func_i->m_val = (m_uint)(func->code ?: (VM_Code)func); + const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : PushStaticCode); + func_i->m_val = (m_uint)(f->code ?: (VM_Code)f); return GW_OK; } - if(func->def->base->tmpl) + if(f->def->base->tmpl) emit_add_instr(emit, DotTmplVal); else { - const Instr instr = emit_add_instr(emit, GET_FLAG(func, member) ? DotFunc : DotStaticFunc); - instr->m_val = exp_self(member)->type->e->d.func->vt_index; + const Instr instr = emit_add_instr(emit, GET_FLAG(f, member) ? DotFunc : DotStaticFunc); + instr->m_val = f->vt_index; } return GW_OK; } @@ -1683,7 +1684,7 @@ ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot* member) { emit_add_instr(emit, GWOP_EXCEPT); } if(isa(exp_self(member)->type, t_function) > 0 && isa(exp_self(member)->type, t_fptr) < 0) - return emit_member_func(emit, member, value->d.func_ref); + return emit_member_func(emit, member); return (GET_FLAG(value, member) ? emit_member : emit_dot_static_import_data) (emit, value, exp_self(member)->emit_var); } diff --git a/src/parse/check.c b/src/parse/check.c index b75a4276..a3b0d31f 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -650,7 +650,7 @@ ANN static void print_arg(Arg_List e) { while((e = e->next) && gw_err(",")); } -ANN2(1) static void* function_alternative(const Env env, const Type f, const Exp args, const loc_t pos){ +ANN2(1) static void function_alternative(const Env env, const Type f, const Exp args, const loc_t pos){ env_err(env, pos, _("argument type(s) do not match for function. should be :")); Func up = f->e->d.func; do { @@ -660,7 +660,6 @@ ANN2(1) static void* function_alternative(const Env env, const Type f, const Exp gw_err("\n"); } while((up = up->next)); args ? print_current_args(args) : (void)gw_err(_("and not:\n \033[32mvoid\033[0m\n")); - return NULL; } ANN static m_uint get_type_number(ID_List list) { @@ -780,8 +779,12 @@ ANN Type check_exp_call1(const Env env, const Exp_Call *exp) { if(GET_FLAG(exp->func->type, func)) return check_exp_call_template(env, (Exp_Call*)exp); const Func func = find_func_match(env, exp->func->type->e->d.func, exp->args); - return (exp_self(exp)->d.exp_call.m_func = func) ? - func->def->base->ret_type : function_alternative(env, exp->func->type, exp->args, exp_self(exp)->pos); + if((exp_self(exp)->d.exp_call.m_func = func)) { + exp->func->type = func->value_ref->type; + return func->def->base->ret_type; + } + function_alternative(env, exp->func->type, exp->args, exp_self(exp)->pos); + return GW_ERROR; } ANN static Type check_exp_binary(const Env env, const Exp_Binary* bin) {