File tree Expand file tree Collapse file tree 6 files changed +36
-4
lines changed
src/arkreactor/Compiler/NameResolution
resources/NameResolutionSuite/hidden_shadowing Expand file tree Collapse file tree 6 files changed +36
-4
lines changed Original file line number Diff line number Diff line change 77namespace 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 );
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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};
Original file line number Diff line number Diff line change 1+ (import b :foo)
2+ (import c :bar)
3+
4+ (let ok (and (= foo "b:foo") (= bar "c:bar")))
Original file line number Diff line number Diff line change 1+ (let find "b.ark")
2+ (let petrol (fun () find))
3+
4+ (let foo "b:foo")
Original file line number Diff line number Diff line change 1+ (let find "c.ark")
2+ (let test (fun () find))
3+
4+ (let bar "c:bar")
You can’t perform that action at this time.
0 commit comments