Skip to content

Commit e6050b7

Browse files
committed
fix(pm): inherit declared index namespaces exactly
1 parent 0108ee1 commit e6050b7

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/pm/index_route.cppm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,16 @@ Lookup lookup_descriptor(const IndexRoute& route,
159159
// BareDefault=false` matches prepare's disambiguation: a descriptor
160160
// with no namespace is reached through the explicit `(∅, name)` rung
161161
// below, not by being waved through on the default-namespace rung.
162+
// A descriptor served by one declared project index inherits that
163+
// index's namespace when it omits package.namespace. Pass the owning
164+
// index explicitly; leaving this empty turns valid name-only local
165+
// descriptors into false misses (including [indices] default).
166+
const auto* owner = route.find_for_ns(candidate.namespace_);
167+
const std::string_view ownerNs = owner
168+
? std::string_view{owner->name} : std::string_view{};
162169
if (!mcpp::manifest::xpkg_lua_identity_matches(
163170
*lua, candidate.namespace_, candidate.shortName,
164-
/*allowLegacyBareDefault=*/false)) {
171+
/*allowLegacyBareDefault=*/false, ownerNs)) {
165172
continue;
166173
}
167174
auto declaredNs = mcpp::manifest::extract_xpkg_namespace(*lua);

tests/unit/test_pm_index_route.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ TEST(PmIndexRoute, DottedSelectorResolvesThroughItsExactCoordinate) {
8282
EXPECT_EQ(found.hit->coord.shortName, "util");
8383
}
8484

85+
TEST(PmIndexRoute, NameOnlyDescriptorInheritsOwningLocalIndexNamespace) {
86+
LocalIndex idx("name-only");
87+
std::ofstream(idx.root / "pkgs" / "a" / "acme.util.lua") << R"(
88+
package = {
89+
spec = "1",
90+
name = "util",
91+
type = "package",
92+
}
93+
)";
94+
auto indices = local_map(idx);
95+
mcpp::pm::IndexRoute route{ &indices, "/nowhere", nullptr };
96+
97+
auto selector = mcpp::pm::resolve_dependency_selector("acme.util");
98+
auto found = mcpp::pm::lookup_descriptor(route, selector.candidates);
99+
100+
ASSERT_TRUE(found.hit.has_value());
101+
EXPECT_EQ(found.hit->coord.namespace_, "acme");
102+
EXPECT_EQ(found.hit->coord.shortName, "util");
103+
}
104+
85105
TEST(PmIndexRoute, LiteralDottedShortNameNeverMatches) {
86106
LocalIndex idx("literal");
87107
auto indices = local_map(idx);

0 commit comments

Comments
 (0)