From a7aee2fcb3204ee291ba59d6e292b6b53612ba54 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Tue, 1 Jun 2021 22:56:15 +0200 Subject: [PATCH] :art: Improve requested variables checking --- src/parse/check_traits.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) 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++) { -- 2.43.0