From: Jérémie Astor Date: Tue, 1 Jun 2021 20:56:15 +0000 (+0200) Subject: :art: Improve requested variables checking X-Git-Tag: nightly~614 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=a7aee2fcb3204ee291ba59d6e292b6b53612ba54;p=gwion.git :art: Improve requested variables checking --- diff --git a/src/parse/check_traits.c b/src/parse/check_traits.c index 079260cd..f9a938a9 100644 --- a/src/parse/check_traits.c +++ b/src/parse/check_traits.c @@ -12,32 +12,42 @@ #include "import.h" #include "parse.h" -ANN static bool request_var(const Env env, const Type t, const Value request) { - const Value value = nspc_lookup_value0(t->nspc, insert_symbol(request->name)); - if(!value) { - gwerr_basic("missing requested variable", NULL, NULL, - request->from->filename, request->from->loc, 0); - return false; - } +ANN static bool var_match(const Value a, const Value b) { bool error = true; - if(isa(value->type, request->type) < 0) { + if(isa(a->type, a->type) < 0) { gwerr_basic("invalid variable type", NULL, NULL, - value->from->filename, value->from->loc, 0); + a->from->filename, a->from->loc, 0); // can we point to the type decl? error = false; } - if(GET_FLAG(value, const) && !GET_FLAG(request, const)) { + if(GET_FLAG(a, const) && !GET_FLAG(b, const)) { gwerr_basic("variable differs in {/}constness{0}", NULL, NULL, - value->from->filename, value->from->loc, 0); + a->from->filename, a->from->loc, 0); + // can we point to the flag? + error = false; + } + if(GET_FLAG(a, static) && !GET_FLAG(b, static)) { + gwerr_basic("variable differs in {/}storage{0}", NULL, NULL, + a->from->filename, a->from->loc, 0); // can we point to the flag? error = false; } if(error) return true; - gwerr_secondary("from requested variable", request->from->filename, request->from->loc); + gwerr_secondary("from requested variable", b->from->filename, b->from->loc); return error; } +ANN static bool request_var(const Env env, const Type t, const Value request) { + const Value value = nspc_lookup_value0(t->nspc, insert_symbol(request->name)); + if(!value) { + gwerr_basic("missing requested variable", NULL, NULL, + request->from->filename, request->from->loc, 0); + return false; + } + return var_match(value, request); +} + ANN static bool check_trait_variables(const Env env, const Type t, const Trait trait) { bool error = false; for(m_uint i = 0; i < vector_size(&trait->requested_values); i++) {