Skip to content

Commit 7862218

Browse files
committed
Check name and module are never empty
1 parent e7572a3 commit 7862218

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

cpp2rust/converter/translation_rule.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ RuleMap LoadTgtFromIR(const std::filesystem::path &json_path) {
328328
if (name[0] == 'f') {
329329
rule.tgt = ParseExprTgtJSON(*obj);
330330
std::get<ExprTgt>(rule.tgt).name = name;
331-
std::get<ExprTgt>(rule.tgt).validate(json_path.string() + ":" + name);
332331
} else if (name[0] == 't') {
333332
rule.tgt = ParseTypeTgtJSON(*obj);
334333
} else {
@@ -468,6 +467,8 @@ void ExprTgt::validate(const std::string &context) const {
468467
ValidateConsecutiveKeys(params, 'a', 0, context + " params");
469468
ValidateConsecutiveKeys(generics, 'T', 1, context + " generics");
470469
assert(!body.empty() && "ExprTgt body must not be empty");
470+
assert(!name.empty() && "ExprTgt name must not be empty");
471+
assert(!module.empty() && "ExprTgt module must not be empty");
471472
}
472473

473474
std::vector<Rule> Load(const std::filesystem::path &path, Model model) {
@@ -501,6 +502,9 @@ std::vector<Rule> Load(const std::filesystem::path &path, Model model) {
501502
std::vector<Rule> result;
502503
for (auto &[name, rule] : rules) {
503504
assert(!rule.src.empty() && "Rule loaded from IR but has no src");
505+
if (auto *expr_tgt = std::get_if<ExprTgt>(&rule.tgt)) {
506+
expr_tgt->validate(path.string() + ":" + name);
507+
}
504508
result.push_back(std::move(rule));
505509
}
506510
return result;

0 commit comments

Comments
 (0)