diff options
author | Himbeer <himbeer@disroot.org> | 2024-10-08 13:23:00 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-10-08 13:24:20 +0200 |
commit | d8397304ba277bbf0e3780c46400f9abca6adc47 (patch) | |
tree | 9ab8317f627d882895064915d80ffb413332023b | |
parent | 35b55292a4aa99bc72c6f97290c15c139f027706 (diff) |
Check for import name collisions
-rw-r--r-- | src/check.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/check.c b/src/check.c index f6a8576..10ba2bf 100644 --- a/src/check.c +++ b/src/check.c @@ -4,6 +4,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdnoreturn.h> +#include <string.h> #include "lex.h" #include "parse.h" #include "util.h" @@ -23,9 +24,29 @@ error(struct location loc, const char *fmt, ...) } static void +check_import(struct ast_import *imports, int i) +{ + for (int j = 0; j < i; ++j) { + if (j == i) { + continue; + } + + if (!strcmp(imports[j].name, imports[i].name)) { + error(imports[i].loc, + "import collision (previous import at %s:%d:%d)", + imports[j].loc.file, + imports[j].loc.line, + imports[j].loc.column); + } + } +} + +static void check_imports(struct ast_import *imports, int n) { - /* TODO */ + for (int i = 0; i < n; ++i) { + check_import(imports, i); + } } static void |