]> Nishi Git Mirror - gwion.git/commitdiff
:bug: Fix cyclic declaration
authorJérémie Astor <astor.jeremie@wanadoo.fr>
Wed, 6 May 2020 22:51:54 +0000 (00:51 +0200)
committerJérémie Astor <astor.jeremie@wanadoo.fr>
Wed, 6 May 2020 22:51:54 +0000 (00:51 +0200)
src/parse/check.c

index c71144f18ec050d901da3df4290145f1e2a345f1..ce74ee2407bcac89c85149179b79a0f0b4190886 100644 (file)
@@ -167,6 +167,14 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) {
     ERR_O(td_pos(decl->td), _("can't find type"));
   {
     const Type t = get_type(decl->type);
+    if(env->class_def && !env->scope->depth){
+      Type parent = t;
+      while(parent) {
+        if(parent == env->class_def && !GET_FLAG(decl->td, ref))
+          ERR_O(decl->td->pos, "declaration cycle detected. (declare as ref?)")
+        parent = parent->e->parent;
+      }
+    }
     if(!GET_FLAG(t, check) && t->e->def)
       CHECK_BO(ensure_check(env, t))
   }