From: fennecdjay Date: Sun, 21 Jul 2019 09:22:15 +0000 (+0200) Subject: :art: Improve return stmt X-Git-Tag: nightly~2312 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=30987f4367152b034513c8808b09c6bed2508387;p=gwion.git :art: Improve return stmt --- diff --git a/src/parse/check.c b/src/parse/check.c index c141924c..75d7a033 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -996,22 +996,18 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { if(!env->func) ERR_B(stmt_self(stmt)->pos, _("'return' statement found outside function definition")) DECL_OB(const Type, ret_type, = stmt->val ? check_exp(env, stmt->val) : t_void) - if(env->func->value_ref->type == t_lambda) { - if(env->func->def->base->ret_type && - isa(ret_type, env->func->def->base->ret_type) < 0 && - isa(env->func->def->base->ret_type, ret_type) < 0) - ERR_B(stmt_self(stmt)->pos, _("return types do not match for lambda expression")) - env->func->value_ref->type = ret_type; + if(!env->func->def->base->ret_type) { + assert(isa(env->func->value_ref->type, t_lambda) > 0); + env->func->def->base->ret_type = ret_type; return GW_OK; } - if(isa(ret_type, t_null) > 0 && - isa(env->func->def->base->ret_type, t_object) > 0) - return GW_OK; - if(env->func->def->base->ret_type && isa(ret_type, env->func->def->base->ret_type) < 0) + const struct Implicit imp = { stmt->val, env->func->def->base->ret_type, stmt_self(stmt)->pos }; + struct Op_Import opi = { .op=insert_symbol("@implicit"), .lhs=ret_type, .rhs=env->func->def->base->ret_type, + .data=(m_uint)&imp, .pos=stmt_self(stmt)->pos }; + const Type ret = op_check(env, &opi); + if(!ret) ERR_B(stmt_self(stmt)->pos, _("invalid return type '%s' -- expecting '%s'"), ret_type->name, env->func->def->base->ret_type->name) - else //! set default return type for lambdas - env->func->def->base->ret_type = ret_type; return GW_OK; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index fee64381..1739e38b 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -325,7 +325,7 @@ ANN static Func scan_new_func(const Env env, const Func_Def f, const m_str name) } ANN static Type func_type(const Env env, const Func func) { - const Type t = type_copy(env->gwion->mp, t_function); + const Type t = type_copy(env->gwion->mp, func->def->base->td ? t_function : t_lambda); t->name = func->name; t->e->owner = env->curr; if(GET_FLAG(func, member))