From bf5f93cb4e3947a6f214ffae72d38f18b758b00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sun, 22 Oct 2023 16:23:22 +0800 Subject: [PATCH] Add files via upload --- src/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 190b6899..410e9e9c 100644 --- a/src/main.c +++ b/src/main.c @@ -365,12 +365,13 @@ static void add_imported_symbol(struct FileState *fs, const ExportSymbol *es, As static void add_imported_symbols(struct CompileState *compst) { - // TODO: should it be possible for a file to import from itself? - // Should fail with error? for (struct FileState *to = compst->files.ptr; to < End(compst->files); to++) { for (AstImport *imp = to->ast.imports.ptr; imp < End(to->ast.imports); imp++) { struct FileState *from = find_file(compst, imp->resolved_path); assert(from); + if (from->path == to->path) { + fail_with_error(imp->location, "the file itself cannot be imported"); + } for (struct ExportSymbol *es = from->pending_exports; es->name[0]; es++) { if (command_line_args.verbosity >= 2) {