Skip to content

Commit 259442d

Browse files
committed
fix(name resolver): couldn't import two different files with the same symbol names inside, even though both were hidden and prefixed by their file
1 parent 5598b7c commit 259442d

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
namespace Ark::internal
88
{
99
NameResolutionPass::NameResolutionPass(const unsigned debug) :
10-
Pass("NameResolution", debug),
11-
m_ast()
10+
Pass("NameResolution", debug)
1211
{
1312
for (const auto& builtin : Builtins::builtins)
1413
m_language_symbols.emplace(builtin.first);

src/arkreactor/Compiler/NameResolution/ScopeResolver.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ namespace Ark::internal
7070
{
7171
if (auto maybe_fqn = scope->get(name, true); maybe_fqn.has_value())
7272
{
73-
// priorize non-hidden symbols
74-
if ((maybe_name.has_value() && maybe_name.value().ends_with("#hidden")) || !maybe_name.has_value())
73+
// prioritize non-hidden symbols
74+
if ((maybe_name.has_value() &&
75+
maybe_name.value().ends_with("#hidden") &&
76+
!maybe_fqn.value().name.ends_with("#hidden")) ||
77+
!maybe_name.has_value())
7578
maybe_name = maybe_fqn.value().name;
7679
}
7780
}

tests/unittests/Suites/NameResolutionSuite.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,22 @@ ut::suite<"NameResolution"> name_resolution_suite = [] {
163163
expect(a_map.valueType() == Ark::ValueType::True) << "(= (map) \"c:map\")\n";
164164
};
165165
};
166+
167+
"[importing two symbols from different modules with the same hidden symbols should resolve correctly]"_test = [] {
168+
Ark::State state({ lib_path });
169+
170+
should("compile the resource without any error") = [&] {
171+
expect(mut(state).doFile(getResourcePath("NameResolutionSuite/hidden_shadowing/a.ark")));
172+
};
173+
174+
Ark::VM vm(state);
175+
should("return exit code 0") = [&] {
176+
expect(mut(vm).run() == 0_i);
177+
};
178+
179+
should("resolve symbols from all namespaces without generating bad fully qualified names") = [&] {
180+
const auto a_ok = mut(vm).operator[]("ok");
181+
expect(a_ok.valueType() == Ark::ValueType::True) << "(and (= foo \"b:foo\") (= bar \"c:bar\"))\n";
182+
};
183+
};
166184
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(import b :foo)
2+
(import c :bar)
3+
4+
(let ok (and (= foo "b:foo") (= bar "c:bar")))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(let find "b.ark")
2+
(let petrol (fun () find))
3+
4+
(let foo "b:foo")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(let find "c.ark")
2+
(let test (fun () find))
3+
4+
(let bar "c:bar")

0 commit comments

Comments
 (0)