Add "(default)" to conflict warnings in user resolver.

When reporting conflicts between parent and child elements during attachment, the warning message now indicates if a value is derived from the default rather than being explicitly authored in the XML. This improves clarity in conflict resolution warnings.

PiperOrigin-RevId: 936724265
Change-Id: I68c677b19020c19bf0260f5b3b77fe6ca3661bb9
This commit is contained in:
Yuval Tassa
2026-06-23 09:43:38 -07:00
committed by Copybara-Service
parent 5637f74327
commit 080668df42
2 changed files with 56 additions and 5 deletions
+9 -5
View File
@@ -32,7 +32,7 @@ namespace {
// format a numeric value for conflict messages
template <typename T>
std::string fmtVal(T val) {
if constexpr (std::is_same_v<T, mjtNum>) {
if constexpr (std::is_floating_point_v<T>) {
char buf[32];
snprintf(buf, sizeof(buf), "%g", val);
return buf;
@@ -87,8 +87,10 @@ struct Resolver {
// "FIELD: parent has X, child has Y"
auto prefix = [&]() {
return std::string(name) + ": parent has " + fmtVal(pval) +
", child has " + fmtVal(cval);
std::string p_str = fmtVal(pval) + (parent_authored ? "" : " (default)");
std::string c_str = fmtVal(cval) + (child_authored ? "" : " (default)");
return std::string(name) + ": parent has " + p_str +
", child has " + c_str;
};
// only child authored: adopt or keep
@@ -168,8 +170,10 @@ struct Resolver {
// "FIELD: parent has X Y Z, child has X Y Z"
auto prefix = [&]() {
return std::string(name) + ": parent has " + fmtArr(pval, N) +
", child has " + fmtArr(cval, N);
std::string p_str = fmtArr(pval, N) + (parent_authored ? "" : " (default)");
std::string c_str = fmtArr(cval, N) + (child_authored ? "" : " (default)");
return std::string(name) + ": parent has " + p_str +
", child has " + c_str;
};
// only child authored: adopt or keep