commit 5272930df41002ff9215e7d022af3d895f612884
parent f6ef1673462a2f481c0c37ff3512dd961a0dfe78
Author: Lou Woell <lou.woell@posteo.de>
Date: Fri, 10 Oct 2025 04:52:37 +0200
[locate] fix failing tests
Diffstat:
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/cmd/harehelper/+test/locate_test.ha b/cmd/harehelper/+test/locate_test.ha
@@ -199,3 +199,13 @@ fn loc_test_fn (in: str, out: lex::location) void = {
...
});
};
+
+@test fn locate_not_found_module() void = {
+ test::expectabort();
+ loc_test_fn("hare::nothing", lex::location {
+ path = "foo.ha",
+ line = 111,
+ col = 111,
+ ...
+ });
+};
diff --git a/cmd/harehelper/locate.ha b/cmd/harehelper/locate.ha
@@ -49,11 +49,13 @@ fn locate_symbol (
module: bool = false,
) (lex::location | error) = {
- // if no namespace prefix is present look for a declaration in the cwd.
let ns: module::location = if (module) {
+ // if we know id is a module we can use id as the namespace for
+ // the lookup.
yield id;
} else if (len(id) <= 1) {
-
+ // if no namespace prefix is present look for a declaration in
+ // the cwd.
let p = path::init(os::getcwd())!;
let dirname = match (path::peek(&p)) {
case void =>
@@ -62,6 +64,7 @@ fn locate_symbol (
yield s;
};
+ // check if we are in a tag dir.
for (strings::hasprefix(dirname, '+') ||
strings::hasprefix(dirname, '-')) {
path::pop(&p);
@@ -74,12 +77,13 @@ fn locate_symbol (
};
yield &p;
} else {
+ // We don't know whether id is a module or a symbol in a module,
+ // so we treat it as the latter first.
yield ident_ns(id);
};
let (path, src) = match :module (module::find(ctx, ns)) {
case let r: (str, module::srcset) =>
- id = ident_last(id);
yield r;
case let e: module::error =>
match (module::unwrap_error(e)) {
@@ -118,21 +122,21 @@ fn locate_symbol (
match (decl.decl) {
case let d: []ast::decl_const =>
for (let t .. d) {
- found = ast::ident_eq(id, t.ident);
+ found = ast::ident_eq(ident_last(id), t.ident);
if (found) break;
};
case let d: []ast::decl_global =>
for (let t .. d) {
- found = ast::ident_eq(id, t.ident);
+ found = ast::ident_eq(ident_last(id), t.ident);
if (found) break;
};
case let d: []ast::decl_type =>
for (let t .. d) {
- found = ast::ident_eq(id, t.ident);
+ found = ast::ident_eq(ident_last(id), t.ident);
if (found) break;
};
case let d: ast::decl_func =>
- found = ast::ident_eq(id, d.ident);
+ found = ast::ident_eq(ident_last(id), d.ident);
case => void;
};
@@ -145,5 +149,6 @@ fn locate_symbol (
};
};
- return module::not_found;
+ // We try again but this time treat id as a module name.
+ return locate_symbol(ctx, id, true);
};