From: fennecdjay Date: Thu, 25 Apr 2019 18:44:34 +0000 (+0200) Subject: :bug: Fix switch and default label X-Git-Tag: nightly~2523 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=03e73353de76125b9131f3e1a94e0b66136a8a19;p=gwion.git :bug: Fix switch and default label --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 13e4d177..1accd9e1 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1252,7 +1252,7 @@ ANN static m_bool emit_stmt_jump(const Emitter emit, const Stmt_Jump stmt) { GWD if(!stmt->is_label) stmt->data.instr = emit_add_instr(emit, Goto); else { - if(switch_inside(emit->env, stmt_self(stmt)->pos) && !strcmp(s_name(stmt->name), "default")) { + if(switch_inside(emit->env, stmt_self(stmt)->pos) > 0 && !strcmp(s_name(stmt->name), "default")) { // if(!strcmp(s_name(stmt->name), "default")) // vector_release(&stmt->data.v); return switch_default(emit->env, emit_code_size(emit), stmt_self(stmt)->pos); diff --git a/src/oo/switch.c b/src/oo/switch.c index f2aa16d8..5bcbbba6 100644 --- a/src/oo/switch.c +++ b/src/oo/switch.c @@ -141,6 +141,8 @@ ANN m_bool switch_dyn(const Env env) { } ANN m_bool switch_default(const Env env, const m_uint pc, const loc_t pos) { + if(!VLEN(env->scope->swi)) + ERR_B(pos, "'default'case found outside switch statement.") const Switch sw = (Switch)_scope_back(env->scope->swi); if(sw->default_case_index) ERR_B(pos, "default case already defined") @@ -164,6 +166,8 @@ ANN m_uint switch_idx(const Env env) { } ANN m_bool switch_pop(const Env env) { + const Switch sw = (Switch)_scope_back(env->scope->swi); + sw->ok = 1; _scope_pop(env->scope->swi); return GW_OK; } @@ -171,7 +175,7 @@ ANN m_bool switch_pop(const Env env) { ANN m_bool switch_end(const Env env, const loc_t pos) { const Switch sw = (Switch)_scope_pop(env->scope->swi); const vtype index = VKEY(&env->scope->swi->map, VLEN(&env->scope->swi->map) - 1); - sw->ok = 1; +// sw->ok = 1; if(!VLEN(sw->cases) && !VLEN(&sw->exp)) ERR_B(pos, "switch statement with no cases.") map_remove(&env->scope->swi->map, index);