From d3895a56cbcd8a942f071b0d881eb1e2e9852cfa Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 3 Jul 2019 17:41:11 +0200 Subject: [PATCH] :art: Context can be errored --- include/context.h | 1 + src/emit/emit.c | 2 +- src/gwion.c | 4 ++++ src/parse/check.c | 5 +++-- tests/error/func_exist.gw | 2 -- 5 files changed, 9 insertions(+), 5 deletions(-) delete mode 100644 tests/error/func_exist.gw diff --git a/include/context.h b/include/context.h index 8b70552a..3abafca3 100644 --- a/include/context.h +++ b/include/context.h @@ -7,6 +7,7 @@ struct Context_ { Nspc nspc; struct Map_ lbls; HAS_OBJ + m_bool error; }; ANN2(2) ANEW Context new_context(MemPool p, const Ast, const m_str); diff --git a/src/emit/emit.c b/src/emit/emit.c index 290722cd..a50ac62f 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1285,7 +1285,7 @@ ANN static m_bool emit_stmt_jump(const Emitter emit, const Stmt_Jump stmt) { if(!stmt->is_label) stmt->data.instr = emit_add_instr(emit, Goto); else { - if(switch_inside(emit->env, stmt_self(stmt)->pos) > 0 && !strcmp(s_name(stmt->name), "default")) + if(!strcmp(s_name(stmt->name), "default") && switch_inside(emit->env, stmt_self(stmt)->pos) > 0) return switch_default(emit->env, emit_code_size(emit), stmt_self(stmt)->pos); if(!stmt->data.v.ptr) ERR_B(stmt_self(stmt)->pos, _("illegal case")) diff --git a/src/gwion.c b/src/gwion.c index 6ed44bb3..774f2293 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -4,6 +4,7 @@ #include "oo.h" #include "vm.h" #include "env.h" +#include "context.h" #include "type.h" #include "func.h" #include "value.h" @@ -106,6 +107,8 @@ ANN void gwion_end(const Gwion gwion) { } ANN void env_err(const Env env, const struct YYLTYPE* pos, const m_str fmt, ...) { + if(env->context->error) + return; if(env->class_def) gw_err(_("in class: '%s'\n"), env->class_def->name); if(env->func) @@ -117,4 +120,5 @@ ANN void env_err(const Env env, const struct YYLTYPE* pos, const m_str fmt, ...) va_end(arg); fprintf(stderr, "\n"); loc_err(pos, env->name); + env->context->error = 1; } diff --git a/src/parse/check.c b/src/parse/check.c index ac074915..c8cba0e4 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -611,8 +611,9 @@ ANN static Type check_exp_call_template(const Env env, const Exp_Call *exp) { } ANN static m_bool check_exp_call1_check(const Env env, const Exp exp) { - if(!check_exp(env, exp)) - ERR_B(exp->pos, _("function call using a non-existing function")) + CHECK_OB(check_exp(env, exp)) +// if(!check_exp(env, exp)) +// ERR_B(exp->pos, _("function call using a non-existing function")) if(isa(exp->type, t_function) < 0) ERR_B(exp->pos, _("function call using a non-function value")) return GW_OK; diff --git a/tests/error/func_exist.gw b/tests/error/func_exist.gw deleted file mode 100644 index da0581ce..00000000 --- a/tests/error/func_exist.gw +++ /dev/null @@ -1,2 +0,0 @@ -// [contains] function call using a non-existing function - test(); -- 2.43.0