diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-05-08 16:17:37 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-05-08 16:17:37 -0400 |
commit | 1fac85b953b4a522e6b03fafa97c25a61e1c62ea (patch) | |
tree | 4ef588205feedac82b16dc05e7a72f058c087ebe /types.c | |
parent | 5dabbe87ed4e86fa0306fd9ef11e7a7fee2a6ddb (diff) |
allow use of global constant before declaring it, get rid of weird Location comparison
Diffstat (limited to 'types.c')
-rw-r--r-- | types.c | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -845,20 +845,22 @@ top:; t->flags |= TYPE_IS_RESOLVED; /* for function templates */ return true; } else { - if (where.start <= d->where.end) { + if (d->flags & DECL_INFER) { char *s = ident_to_str(i); - err_print(where, "Use of identifier %s before its declaration.", s); - info_print(d->where, "%s will be declared here.", s); + err_print(where, "Use of identifier %s before it has been inferred. You are trying to do stuff with inference which toc doesn't support.", s); free(s); return false; - } else { - if (d->flags & DECL_INFER) { - err_print(where, "Use of identifier before it has been inferred. You are trying to do stuff with inference which toc doesn't support."); - return false; - } - /* let's type the declaration, and redo this (for evaling future functions) */ + } + if ((d->flags & DECL_IS_CONST) && (tr->block == NULL)) { + /* let's type the declaration, and redo this (for evaling future constants) */ if (!types_decl(tr, d)) return false; goto top; + } else { + char *s = ident_to_str(i); + err_print(where, "Use of %s before its declaration.", s); + info_print(d->where, "%s will be declared here.", s); + free(s); + return false; } } } @@ -2074,7 +2076,7 @@ static Status types_expr(Typer *tr, Expression *e) { } if (undeclared) { char *s = cstr(e->ident_str.str, e->ident_str.len); - err_print(e->where, "Undeclared identifier \"%s\".", s); + err_print(e->where, "Undeclared identifier '%s'.", s); free(s); return false; } |