From: Jérémie Astor Date: Thu, 21 May 2020 21:21:26 +0000 (+0200) Subject: :art: type_cyclic X-Git-Tag: nightly~1531 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=509b35300aba40c20b3c71b1263e4dfe97083d60;p=gwion.git :art: type_cyclic --- diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 0f62b29d..a3f65a2b 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -10,12 +10,15 @@ ANN static m_bool scan1_stmt_list(const Env env, Stmt_List list); ANN static m_bool scan1_stmt(const Env env, Stmt stmt); ANN static inline m_bool type_cyclic(const Env env, const Type t, const Type_Decl *td) { - Type parent = t->e->parent; - while(parent) { - if(parent == env->class_def) - ERR_B(td_pos(td), _("%s declared inside %s\n."), t->name, t == env->class_def ? "itself" : env->class_def->name); - parent = parent->e->parent; - } + Type owner = env->class_def; + do { + Type parent = t; + while(parent) { + if(parent == owner) + ERR_B(td_pos(td), _("%s declared inside %s"), t->name, owner->name); + parent = parent->e->parent; + } + } while((owner = owner->e->owner_class)); return GW_OK; } @@ -37,7 +40,8 @@ ANN static m_bool type_recursive(const Env env, const Type_Decl *td, const Type ANN static Type scan1_type(const Env env, Type_Decl* td) { DECL_OO(const Type, type, = known_type(env, td)) const Type t = get_type(type); - CHECK_BO(type_cyclic(env, t, td)) + if(!env->func && env->class_def) + CHECK_BO(type_cyclic(env, t, td)) if(!GET_FLAG(t, scan1) && t->e->def) CHECK_BO(ensure_scan1(env, t)) return type;