From: Jérémie Astor Date: Sun, 16 May 2021 21:13:51 +0000 (+0200) Subject: :art: Unify noret checks X-Git-Tag: nightly~646 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=11115d1a4daa74a3653edf75b30727f96dadc3ec;p=gwion.git :art: Unify noret checks --- diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 57eaa8b2..1bca68e3 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -378,14 +378,19 @@ ANN static m_bool scan1_args(const Env env, Arg_List list) { return GW_OK; } +ANN static Type scan1_noret(const Env env, const Func_Base *base) { + DECL_OO(const Type, t, = known_type(env, base->td)); + if(!tflag(t, tflag_noret)) + return t; + ERR_O(base->pos, _("Can't use type `{+G}%s{0}` for return"), + t->name); +} + ANN static m_bool _scan1_fdef_base_tmpl(const Env env, Func_Base *base) { ID_List id = base->tmpl->list; do nspc_add_type(env->curr, id->xid, env->gwion->type[et_auto]); while((id = id->next)); - CHECK_OB((base->ret_type = known_type(env, base->td))); - if(tflag(base->ret_type, tflag_noret)) - ERR_B(base->pos, _("Can't use type `{+G}%s{0}` for return"), - base->ret_type->name); + CHECK_OB((base->ret_type = scan1_noret(env, base))); if(base->args) { Arg_List arg = base->args; do CHECK_OB(known_type(env, arg->td)); @@ -409,10 +414,7 @@ ANN m_bool scan1_fptr_def(const Env env, const Fptr_Def fptr) { fptr->type = nspc_lookup_type0(env->curr, fptr->base->xid); } const Func_Def fdef = fptr->base->func->def; - CHECK_OB((fdef->base->ret_type = scan1_type(env, fdef->base->td))); - if(tflag(fdef->base->ret_type, tflag_noret)) - ERR_B(fdef->base->pos, _("Can't use type `{+G}%s{0}` for return"), - fdef->base->ret_type->name); + CHECK_OB((fdef->base->ret_type = scan1_noret(env, fdef->base))); if(!fdef->base->args) return GW_OK; RET_NSPC(scan1_args(env, fdef->base->args)) @@ -572,12 +574,8 @@ ANN m_bool scan1_fbody(const Env env, const Func_Def fdef) { } ANN m_bool scan1_fdef(const Env env, const Func_Def fdef) { - if(fdef->base->td) { - CHECK_OB((fdef->base->ret_type = known_type(env, fdef->base->td))); - if(tflag(fdef->base->ret_type, tflag_noret)) - ERR_B(fdef->base->pos, _("Can't use type `{+G}%s{0}` for return"), - fdef->base->ret_type->name); - } + if(fdef->base->td) + CHECK_OB((fdef->base->ret_type = scan1_noret(env, fdef->base))); if(fbflag(fdef->base, fbflag_internal)) CHECK_BB(scan_internal(env, fdef->base)); else if(fbflag(fdef->base, fbflag_op) && env->class_def)