From: fennecdjay Date: Sun, 20 Oct 2019 14:53:25 +0000 (+0200) Subject: :art: Error message on return type mismatch X-Git-Tag: nightly~2120 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=8deda308f1a772053073189ff1f6d7fb663f698b;p=gwion.git :art: Error message on return type mismatch --- diff --git a/src/parse/check.c b/src/parse/check.c index 6942acf4..0b208e4e 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1086,8 +1086,13 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { } if(isa(ret_type, env->func->def->base->ret_type) > 0) return GW_OK; - if(stmt->val) - return check_implicit(env, stmt->val, env->func->def->base->ret_type); + if(stmt->val) { + const m_bool ret = check_implicit(env, stmt->val, env->func->def->base->ret_type); + if(ret > 0) + return ret; + ERR_B(stmt_self(stmt)->pos, _("invalid return type: got '%s', expected '%s'"), + ret_type->name, env->func->def->base->ret_type->name) + } if(isa(env->func->def->base->ret_type, env->gwion->type[et_void]) > 0) return GW_OK; ERR_B(stmt_self(stmt)->pos, _("missing value for return statement")) diff --git a/tests/error/return_expected.gw b/tests/error/return_expected.gw new file mode 100644 index 00000000..8306dac1 --- /dev/null +++ b/tests/error/return_expected.gw @@ -0,0 +1,2 @@ +#! [contains] invalid return type +fun int test() { return me; }