]> Nishi Git Mirror - gwion.git/commitdiff
:bug: Fix class recursion
authorfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 3 May 2019 12:40:39 +0000 (14:40 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 3 May 2019 12:41:12 +0000 (14:41 +0200)
src/parse/check.c
src/parse/scan1.c
tests/error/recursive_class_def.gw [new file with mode: 0644]
tests/error/self_extend.gw [deleted file]

index cd46edc075a67bbd249ba7f1b374905728f241b3..2682819a9bda20a0a45e7f4eb34f20cc7ee57b76 100644 (file)
@@ -839,6 +839,8 @@ ANN static m_bool do_stmt_auto(const Env env, const Stmt_Auto stmt) {
 }
 
 ANN static m_bool cond_type(const Env env, const Exp e) {
+  if(e->next)
+    ERR_B(e->pos, "conditional must be a single expression")
   const Type t = e->type;
   if(isa(t, t_int) > 0)
     return GW_OK;
index 49bca396ead94332f0219f249d0c99feb125b7d6..76fdcb349ecf125cb0a0b0b9480ce923e94ee4ef 100644 (file)
@@ -316,6 +316,12 @@ ANN static m_bool scan1_class_parent(const Env env, const Class_Def cdef) {
   CHECK_OB(parent)
   if(parent == t_undefined)
     return GW_OK;
+  Type t = parent;
+  while(t) {
+    if(cdef->base.type == t)
+      ERR_B(pos, "recursive (%s <= %s) class declaration.", cdef->base.type->name, t->name);
+    t = t->parent;
+  }
   if(parent == cdef->base.type)
     ERR_B(pos, "class '%s' cannot extend itself", cdef->base.type->name);
   if(isa(cdef->base.type->parent, t_object) < 0)
diff --git a/tests/error/recursive_class_def.gw b/tests/error/recursive_class_def.gw
new file mode 100644 (file)
index 0000000..6d30f40
--- /dev/null
@@ -0,0 +1,16 @@
+// [contains] recursive
+class C {}
+class D extends C {}
+class E extends F {}
+class F extends E {}
+class G extends C {}
+
+C c;
+D d;
+E e;
+F f;
+G g;
+<<<f $ D>>>;
+<<< [ f, g ] >>>;
+<<<maybe ? f : D>>>;
+<<<c, " ", d, " ", e, " ", g>>>;
diff --git a/tests/error/self_extend.gw b/tests/error/self_extend.gw
deleted file mode 100644 (file)
index 23869cf..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-// [contains] cannot extend itself
-class C extends C {
-
-}
-C c;
-<<<c>>>;
\ No newline at end of file