From 115c75692bab91f62ff07ab3567a29436ab04515 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 26 Feb 2024 23:02:09 -0500 Subject: Better error checking --- compile.c | 3 +++ environment.c | 6 +++--- 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); } -- cgit v1.2.3