commit ab6106091df0ebaa3b6248bc9f4d472e36fae654
parent 76a105a0347e7ea3248d5b31f71bc7b2dad56664
Author: Lou Woell <lou.woell@posteo.de>
Date: Thu, 11 Sep 2025 14:17:27 +0200
correctly locate multiple bindings
Diffstat:
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/cmd/harehelper/+test/list_test.ha b/cmd/harehelper/+test/list_test.ha
@@ -1,5 +1,4 @@
use dirs;
-use fmt;
use hare::module;
use hare::parse;
use os;
diff --git a/cmd/harehelper/+test/locate_test.ha b/cmd/harehelper/+test/locate_test.ha
@@ -5,6 +5,8 @@ use hare::parse;
use os;
use strings;
+const s = 1, d = 2;
+
fn loc_test_fn (in: str, out: lex::location) void = {
const ctx = module::context {
harepath = os::tryenv("HAREPATH", HAREPATH),
@@ -14,7 +16,7 @@ fn loc_test_fn (in: str, out: lex::location) void = {
case void =>
yield dirs::cache("hare");
},
- tags = ["linux"],
+ tags = ["linux", "test"],
};
const id = parse::identstr(in)!;
@@ -37,6 +39,16 @@ fn loc_test_fn (in: str, out: lex::location) void = {
});
};
+
+@test fn locate_multiple() void = {
+ loc_test_fn("cmd::harehelper::d", lex::location {
+ path = "locate_test.ha",
+ line = 6,
+ col = 13,
+ ...
+ });
+};
+
// @test fn locate_local() void = {
// loc_test_fn("cmd::harehelper::main", lex::location {
// path = "helper.ha",
diff --git a/cmd/harehelper/locate.ha b/cmd/harehelper/locate.ha
@@ -68,21 +68,25 @@ fn locate_symbol (
let decls = scan(s)!;
defer decls_finish(decls);
- let found = false;
-
for (let decl .. decls) {
+
+ let found = false;
+
match (decl.decl) {
case let d: []ast::decl_const =>
for (let t .. d) {
found = ast::ident_eq(id, t.ident);
+ if (found) break;
};
case let d: []ast::decl_global =>
for (let t .. d) {
found = ast::ident_eq(id, t.ident);
+ if (found) break;
};
case let d: []ast::decl_type =>
for (let t .. d) {
found = ast::ident_eq(id, t.ident);
+ if (found) break;
};
case let d: ast::decl_func =>
found = ast::ident_eq(id, d.ident);