From: Jérémie Astor Date: Thu, 12 Aug 2021 12:09:57 +0000 (+0200) Subject: :art: Improve warnings X-Git-Tag: nightly~470^2~101 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=a4ec6f6471122c0b4a0457dcf2abbc89ae45367c;p=gwion.git :art: Improve warnings --- diff --git a/ast b/ast index b340a23a..83f85714 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit b340a23a9f3902e3a7633fcddf1bd22d8d03814e +Subproject commit 83f857146706db6c97b5489152cded2be8083852 diff --git a/src/emit/emit.c b/src/emit/emit.c index 7021c684..cda5ffb0 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -942,6 +942,14 @@ ANN static void set_late(const Gwion gwion, const Exp_Decl *decl, UNSET_FLAG(v, late); } +static inline bool _late_array(const Array_Sub array) { + return array && !array->exp; +} + +ANN static inline bool late_array(const Type_Decl *td, const Var_Decl var) { + return _late_array(td->array) || _late_array(var->array); +} + ANN static m_bool emit_decl(const Emitter emit, const Exp_Decl *decl) { const m_bool global = GET_FLAG(decl->td, global); const uint var = exp_getvar(exp_self(decl)); @@ -965,10 +973,10 @@ ANN static m_bool emit_decl(const Emitter emit, const Exp_Decl *decl) { CHECK_BB(op_emit(emit, &opi)); } set_late(emit->gwion, decl, list->self); - if (GET_FLAG(array_base(v->type), abstract) && !GET_FLAG(decl->td, late) && - GET_FLAG(v, late)) { - env_warn(emit->env, decl->td->pos, _("Type '%s' is abstract, use late"), - v->type->name); + if ((GET_FLAG(array_base(v->type), abstract) && !GET_FLAG(decl->td, late) && + GET_FLAG(v, late)) || late_array(decl->td, list->self)) { + env_warn(emit->env, decl->td->pos, _("Type '%s' is abstract, use {+G}late{0} instead of {G+}%s{0}"), + v->type->name, !GET_FLAG(decl->td, const) ? "var" : "const"); } } while ((list = list->next)); return GW_OK; diff --git a/src/gwion.c b/src/gwion.c index 5de60fa6..d2216c74 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -175,11 +175,25 @@ ANN static void env_xxx(const Env env, const loc_t pos, const m_str fmt, #endif } +ANN static void _env_warn(const Env env, const loc_t pos, const m_str fmt, + va_list arg) { +#ifndef __FUZZING__ + va_list tmpa; + va_copy(tmpa, arg); + const int size = vsnprintf(NULL, 0, fmt, tmpa); + va_end(tmpa); + char c[size + 1]; + vsprintf(c, fmt, arg); + gwerr_warn(c, NULL, NULL, env->name, pos); + env_error_footer(env); +#endif +} + ANN void env_warn(const Env env, const loc_t pos, const m_str fmt, ...) { #ifndef __FUZZING__ va_list arg; va_start(arg, fmt); - env_xxx(env, pos, fmt, arg); + _env_warn(env, pos, fmt, arg); va_end(arg); #endif }