diff options
-rw-r--r-- | test.toc | 14 | ||||
-rw-r--r-- | types.c | 14 |
2 files changed, 16 insertions, 12 deletions
@@ -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}; @@ -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); |