From 46c3baff31b836b752081d2bdd6bc0561c798968 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 17 May 2021 13:30:03 +0200 Subject: [PATCH] :art: Support index in 'repeat' loops (more) --- fmt | 2 +- src/parse/scan1.c | 21 ++++++++++++--------- tests/tree/repeat_idx_shadow.gw | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/fmt b/fmt index 2053f83e..99588790 160000 --- a/fmt +++ b/fmt @@ -1 +1 @@ -Subproject commit 2053f83ec266a59dc070daab79bfc595ce9cb5d5 +Subproject commit 9958879019a9bca3aaf3cb92f73aff5c516d3ec3 diff --git a/src/parse/scan1.c b/src/parse/scan1.c index adfc6272..1df28fda 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -303,23 +303,26 @@ ANN static inline m_bool stmt_each_defined(const restrict Env env, const Stmt_Ea return GW_OK; } -ANN static inline m_bool shadow_err(const Env env, const Symbol sym, const loc_t loc) { - ERR_B(loc, _("argument '%s' shadows a previously defined variable"), - s_name(sym)) +ANN static inline m_bool shadow_err(const Env env, const Value v, const loc_t loc) { + gwerr_basic(_("shadowing a previously defined variable"), NULL, NULL, env->name, loc, 0); + gwerr_secondary(_("defined here"), v->from->filename, v->from->loc); + env->context->error = true; + return GW_ERROR; } ANN static inline m_bool shadow_arg(const Env env, const Symbol sym, const loc_t loc) { Nspc nspc = env->curr; - do if(nspc_lookup_value0(nspc, sym)) - return shadow_err(env, sym, loc); - while((nspc = nspc->parent)); + do { + const Value v = nspc_lookup_value0(nspc, sym); + if(v) + return shadow_err(env, v, loc); + } while((nspc = nspc->parent)); return GW_OK; } ANN static inline m_bool shadow_var(const Env env, const Symbol sym, const loc_t loc) { - if(nspc_lookup_value1(env->curr, sym)) - return shadow_err(env, sym, loc); - return GW_OK; + const Value v = nspc_lookup_value1(env->curr, sym); + return !v ? GW_OK : shadow_err(env, v, loc); } #define describe_ret_nspc(name, type, prolog, exp) describe_stmt_func(scan1, name, type, prolog, exp) diff --git a/tests/tree/repeat_idx_shadow.gw b/tests/tree/repeat_idx_shadow.gw index 2b5d7e95..1c01437a 100644 --- a/tests/tree/repeat_idx_shadow.gw +++ b/tests/tree/repeat_idx_shadow.gw @@ -1,4 +1,4 @@ -#! [contains] shadows a previously defined variable +#! [contains] shadowing a previously defined variable var int i; repeat(i, 12); -- 2.43.0