aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-26 23:02:09 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-26 23:02:09 -0500
commit115c75692bab91f62ff07ab3567a29436ab04515 (patch)
treec00e40db70cf7b76af68aa7a6a661008d33feeca
parent8f5a40b9445fa319f4855cba69e7a795de845307 (diff)
Better error checking
-rw-r--r--compile.c3
-rw-r--r--environment.c6
2 files changed, 6 insertions, 3 deletions
diff --git a/compile.c b/compile.c
index 464c22f1..c6e6ddf5 100644
--- a/compile.c
+++ b/compile.c
@@ -846,6 +846,9 @@ CORD compile(env_t *env, ast_t *ast)
auto test = Match(ast, DocTest);
CORD src = heap_strn(test->expr->start, (size_t)(test->expr->end - test->expr->start));
type_t *expr_t = get_type(env, test->expr);
+ if (!expr_t)
+ code_err(test->expr, "I couldn't figure out the type of this expression");
+
if (test->expr->tag == Declare) {
auto decl = Match(test->expr, Declare);
return CORD_asprintf(
diff --git a/environment.c b/environment.c
index 9ce52bcd..6957f26d 100644
--- a/environment.c
+++ b/environment.c
@@ -12,14 +12,14 @@ typedef struct {
binding_t binding;
} ns_entry_t;
-static type_t *namespace_type(table_t *ns)
+static type_t *namespace_type(const char *name, table_t *ns)
{
arg_t *fields = NULL;
for (int64_t i = Table_length(ns); i >= 1; i--) {
struct {const char *name; binding_t binding; } *entry = Table_entry(ns, i);
fields = new(arg_t, .next=fields, .name=entry->name, .type=entry->binding.type);
}
- return Type(StructType, .fields=fields);
+ return Type(StructType, .name=name, .fields=fields);
}
env_t *new_compilation_unit(void)
@@ -63,7 +63,7 @@ env_t *new_compilation_unit(void)
};
for (size_t i = 0; i < sizeof(global_types)/sizeof(global_types[0]); i++) {
- Table_str_set(env->globals, global_types[i].name, namespace_type(&global_types[i].namespace));
+ Table_str_set(env->globals, global_types[i].name, namespace_type(global_types[i].name, &global_types[i].namespace));
Table_str_set(env->types, global_types[i].name, global_types[i].type);
}