diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-04-21 14:58:33 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-04-21 14:58:33 -0400 |
| commit | 3590bf34071bfdfe4d18bb8b32e4c88869bc5f7b (patch) | |
| tree | 57416b6d0a2f0dafa2b9ea7f56f1452ea1fdbf6e /typecheck.c | |
| parent | 3f10460a6e04f014d3fe7a911f6afa844f975585 (diff) | |
Better imports for types
Diffstat (limited to 'typecheck.c')
| -rw-r--r-- | typecheck.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/typecheck.c b/typecheck.c index bd03588a..72551d97 100644 --- a/typecheck.c +++ b/typecheck.c @@ -21,6 +21,19 @@ type_t *parse_type_ast(env_t *env, type_ast_t *ast) const char *name = Match(ast, VarTypeAST)->name; type_t *t = Table$str_get(*env->types, name); if (t) return t; + while (strchr(name, '.')) { + char *module_name = heap_strn(name, strcspn(name, ".")); + binding_t *b = get_binding(env, module_name); + if (!b || b->type->tag != ModuleType) + code_err(ast, "I don't know a module with the name '%s'", module_name); + + env_t *imported = Table$str_get(*env->imports, Match(b->type, ModuleType)->name); + assert(imported); + env = imported; + name = strchr(name, '.') + 1; + t = Table$str_get(*env->types, name); + if (t) return t; + } code_err(ast, "I don't know a type with the name '%s'", name); } case PointerTypeAST: { |
