From: Jérémie Astor Date: Mon, 28 Mar 2022 18:33:42 +0000 (+0200) Subject: :art: correct variable form parent inference X-Git-Tag: nightly~351 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=4b9a57342504abe6ef864c33896a99d90aebc31a;p=gwion.git :art: correct variable form parent inference --- diff --git a/src/parse/check.c b/src/parse/check.c index f28b5641..a546b494 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -274,7 +274,10 @@ ANN m_bool not_from_owner_class(const Env env, const Type t, const Value v, ANN static inline Value get_value(const Env env, const Symbol sym) { const Value value = nspc_lookup_value1(env->curr, sym); - if (value) return value; + if(value) { + if (!value->from->owner_class || isa(env->class_def, value->from->owner_class) > 0) + return value; + } if (env->func && env->func->def->base->values) return (Value)scope_lookup1(env->func->def->base->values, (vtype)sym); return NULL; diff --git a/tests/tree/var_from_parent.gw b/tests/tree/var_from_parent.gw new file mode 100644 index 00000000..79be61d0 --- /dev/null +++ b/tests/tree/var_from_parent.gw @@ -0,0 +1,17 @@ +#! [contains] Gotcha! +class ParentClass { + var string name; +} + +class UncleClass { + + var string name; + + class ChildClass extends ParentClass { + "Gotcha!" => name; + } +} + +var UncleClass.ChildClass c; + +<<< c.name >>>;