commit b8725d36fc808349472909c6957a7b72d0aca760
parent 091f53764256466a567f69bcf149324d726b93ab
Author: Lou Woell <lou.woell@posteo.de>
Date:   Thu, 11 Sep 2025 16:23:18 +0200

[resolve] return void when name not imported.

Diffstat:
Mcmd/harehelper/+test/resolve_test.ha | 14++++++++++++++
Mcmd/harehelper/resolve.ha | 17++++++++++-------
2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/cmd/harehelper/+test/resolve_test.ha b/cmd/harehelper/+test/resolve_test.ha @@ -5,6 +5,7 @@ use hare::parse; use m = math; use memio::{concat, dynamic}; use os; +use test; fn resolve_test_fn (in: str, out: str) void = { const ctx = context { @@ -35,6 +36,7 @@ fn resolve_test_fn (in: str, out: str) void = { }; @test fn resolve_wildcard_module () void = { + test::expectabort(); resolve_test_fn("hare::module", "hare::module"); }; @@ -43,14 +45,26 @@ fn resolve_test_fn (in: str, out: str) void = { }; @test fn resolve_member_module () void = { + test::expectabort(); resolve_test_fn("memio", "memio"); }; @test fn resolve_module_noimport () void = { + test::expectabort(); resolve_test_fn("bufio", "bufio"); }; +@test fn resolve_module_import () void = { + resolve_test_fn("parse", "hare::parse"); +}; + +@test fn resolve_module_fullname_import () void = { + test::expectabort(); + resolve_test_fn("hare::parse", "hare::parse"); +}; + @test fn resolve_symbol_noimport () void = { + test::expectabort(); resolve_test_fn("bufio::finish", "bufio::finish"); }; diff --git a/cmd/harehelper/resolve.ha b/cmd/harehelper/resolve.ha @@ -26,9 +26,9 @@ use os; fn resolve(cmd: getopt::command, ctx: *module::context) void = { - if(len(cmd.args) == 0) fmt::fatal("Expected Argument"); + if (len(cmd.args) == 0) fmt::fatal("Expected Argument"); - let id = match(parse::identstr(cmd.args[0])){ + let id = match (parse::identstr(cmd.args[0])) { case let id: ast::ident => yield id; case let e: parse::error => @@ -43,11 +43,12 @@ fn resolve(cmd: getopt::command, ctx: *module::context) void = { return void; }; - match (find_uid(ctx, id, file)) { + match (resolve_uid(ctx, id, file)) { case let id_exp: ast::ident => printident(id_exp); ast::ident_free(id_exp); - case => void; + case => + printident(id); }; }; @@ -67,7 +68,9 @@ fn list_imports (path: str) []ast::import = { return parse::imports(&lexer)!; }; -fn find_uid ( +// Resolves id based on imports in file at path. Returns void when id is not +// imported in file. Returned [[ast::ident]] must be freed by caller. +fn resolve_uid ( ctx: *module::context, id: ast::ident, path: str @@ -104,7 +107,7 @@ fn find_uid ( for (let s .. list) { found_import = ast::ident_eq(s, id); - if (found_import){ + if (found_import) { interned = true; break; }; @@ -126,5 +129,5 @@ fn find_uid ( }; }; - return id; + return void; };