From 8deda308f1a772053073189ff1f6d7fb663f698b Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 20 Oct 2019 16:53:25 +0200 Subject: [PATCH] :art: Error message on return type mismatch --- src/parse/check.c | 9 +++++++-- tests/error/return_expected.gw | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/error/return_expected.gw 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; } -- 2.43.0