From 4b9a57342504abe6ef864c33896a99d90aebc31a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 28 Mar 2022 20:33:42 +0200 Subject: [PATCH] :art: correct variable form parent inference --- src/parse/check.c | 5 ++++- tests/tree/var_from_parent.gw | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/tree/var_from_parent.gw 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 >>>; -- 2.43.0