From f65fa40de3223ca12fa750d89e2db1f2e6dbba8d Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 10 Jan 2020 10:37:42 -0500 Subject: allow direct circular dependencies --- test.toc | 14 ++++++++------ types.c | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/test.toc b/test.toc index 2855bb1..3170b55 100644 --- a/test.toc +++ b/test.toc @@ -8,13 +8,15 @@ putf ::= fn(x: float) { }; // point ::= pkg "point"; -Foo ::= struct { - b: &Bar; -}; +// Foo ::= struct { + // b: Bar; +// }; -Bar ::= struct { - f: &Foo; -}; +// Bar ::= struct { + // f: Foo; +// }; + +Foo ::= struct { p: &Foo; }; main ::= fn() { f::=fn(t::Type)Type {t}; diff --git a/types.c b/types.c index 2de05c0..5abba99 100644 --- a/types.c +++ b/types.c @@ -414,6 +414,14 @@ static bool type_of_ident(Typer *tr, Location where, Identifier i, Type *t) { err_print(where, "Variables cannot be captured into inner functions (but constants can)."); return false; } + if ((d->flags & DECL_HAS_EXPR) && (d->expr.kind == EXPR_TYPE)) { + /* allow using a type before declaring it */ + t->kind = TYPE_BUILTIN; + t->builtin = BUILTIN_TYPE; + t->flags = TYPE_IS_RESOLVED; + return true; + } + /* are we inside this declaration? */ typedef Declaration *DeclarationPtr; arr_foreach(tr->in_decls, DeclarationPtr, in_decl) { @@ -441,12 +449,6 @@ static bool type_of_ident(Typer *tr, Location where, Identifier i, Type *t) { /* allow using a function before declaring it */ if (!type_of_fn(tr, d->expr.fn, t, 0)) return false; return true; - } else if ((d->flags & DECL_HAS_EXPR) && (d->expr.kind == EXPR_TYPE)) { - /* allow using a type before declaring it */ - t->kind = TYPE_BUILTIN; - t->builtin = BUILTIN_TYPE; - t->flags = TYPE_IS_RESOLVED; - return true; } else { if (where.start <= d->where.end) { char *s = ident_to_str(i); -- cgit v1.2.3