summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test.toc14
-rw-r--r--types.c14
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);