summaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-11-01 13:44:40 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2019-11-01 13:44:40 -0400
commit946da358819261056fad49d9318c6080e9c76c0d (patch)
tree3bf66ba0ed75db8511920b80d1645f06fd19291b /types.c
parentcc33de45174358c13eea4fecaa5f10b094048020 (diff)
fixed that bug!
Diffstat (limited to 'types.c')
-rw-r--r--types.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/types.c b/types.c
index b64fb36..a370ba9 100644
--- a/types.c
+++ b/types.c
@@ -362,21 +362,31 @@ static bool type_resolve(Typer *tr, Type *t, Location where) {
if (!type_resolve(tr, t->slice, where))
return false;
break;
- case TYPE_USER:
- /* just check if it's actually defined */
- if (!ident_typeval(t->user.name)) {
+ case TYPE_USER: {
+ /* check if it's actually defined */
+ IdentDecl *idecl = ident_decl(t->user.name);
+ if (!idecl) {
char *s = ident_to_str(t->user.name);
- IdentDecl *idecl = ident_decl(t->user.name);
- if (idecl) {
- err_print(where, "Use of non-type identifier %s as type.", s);
- info_print(idecl->decl->where, "%s is declared here.", s);
- } else {
- err_print(where, "Use of undeclared type %s.", s);
- }
+ err_print(where, "Use of undeclared type %s.", s);
free(s);
return false;
}
- break;
+ Declaration *decl = idecl->decl;
+ /* now, type the declaration (in case we are using it before its declaration) */
+ if (!types_decl(tr, decl))
+ return false;
+ /* make sure it's actually a type */
+ if (idecl->decl->type.kind != TYPE_TYPE) {
+ char *s = ident_to_str(t->user.name);
+ err_print(where, "Use of non-type identifier %s as type.", s);
+ info_print(decl->where, "%s is declared here.", s);
+ free(s);
+ return s;
+ }
+ /* resolve inner type */
+ Value *val = decl_ident_val(decl, t->user.name);
+ if (!type_resolve(tr, val->type, decl->where)) return false;
+ } break;
case TYPE_STRUCT:
arr_foreach(t->struc.fields, Field, f) {
if (!type_resolve(tr, f->type, where))