Skip to content

Commit dc2b194

Browse files
committed
fix: scanner + validator use qualified name for namespace-aware packages
When mcpp.toml uses `namespace = "mcpplibs"` + `name = "cmdline"`, the scanner was passing the bare short name "cmdline" as packageName to each SourceUnit. The validator then rejected the lib root because `export module mcpplibs.cmdline;` != "cmdline". Fix: scanner builds `qualifiedName = namespace + "." + name` (or bare name if no namespace) and passes that to scan_file. The lib-root check in validate.cppm does the same qualified comparison.
1 parent 940c9d2 commit dc2b194

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/modgraph/scanner.cppm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,16 @@ void scan_one_into(ScanResult& result,
341341
}
342342
for (auto& p : excluded) all_files.erase(p);
343343

344+
// 0.0.6+: use qualified name (namespace.name) so the validator's
345+
// "module must be prefixed by package name" check works when the
346+
// manifest uses an explicit namespace field with a short name.
347+
const std::string qualifiedName =
348+
manifest.package.namespace_.empty()
349+
? manifest.package.name
350+
: manifest.package.namespace_ + "." + manifest.package.name;
351+
344352
for (auto const& f : all_files) {
345-
auto r = scan_file(f, manifest.package.name);
353+
auto r = scan_file(f, qualifiedName);
346354
if (!r) {
347355
result.errors.push_back(r.error());
348356
continue;

src/modgraph/validate.cppm

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,18 @@ ValidateReport validate(const Graph& g,
189189
"lib root '{}' exports a partition '{}' — must be the "
190190
"primary module '{}' (no `:partition` suffix)",
191191
lib_root_rel.string(), m, manifest.package.name)});
192-
} else if (m != manifest.package.name) {
193-
r.errors.push_back({lib_unit->path, std::format(
194-
"lib root '{}' exports module '{}', expected '{}' "
195-
"(must match [package].name)",
196-
lib_root_rel.string(), m, manifest.package.name)});
192+
} else {
193+
// 0.0.6+: compare against qualified name when namespace is set.
194+
const std::string expected =
195+
manifest.package.namespace_.empty()
196+
? manifest.package.name
197+
: manifest.package.namespace_ + "." + manifest.package.name;
198+
if (m != expected) {
199+
r.errors.push_back({lib_unit->path, std::format(
200+
"lib root '{}' exports module '{}', expected '{}' "
201+
"(must match [package].namespace + name)",
202+
lib_root_rel.string(), m, expected)});
203+
}
197204
}
198205
}
199206
}

0 commit comments

Comments
 (0)