]> Nishi Git Mirror - gwion.git/commitdiff
:art: correct variable form parent inference
authorJérémie Astor <fennecdjay@gmail.com>
Mon, 28 Mar 2022 18:33:42 +0000 (20:33 +0200)
committerJérémie Astor <fennecdjay@gmail.com>
Mon, 28 Mar 2022 18:33:42 +0000 (20:33 +0200)
src/parse/check.c
tests/tree/var_from_parent.gw [new file with mode: 0644]

index f28b5641db8b7ddc0261e98848ef67c05345800c..a546b49429c3738bd81c4ee2daee35955f5d6a67 100644 (file)
@@ -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 (file)
index 0000000..79be61d
--- /dev/null
@@ -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 >>>;