Skip to content

Commit 8e5be0d

Browse files
committed
Improve replace_symbolt precondition message
Invariant violations now print out the actual types that were mismatched.
1 parent dbac963 commit 8e5be0d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/util/replace_symbol.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ void replace_symbolt::insert(
2525
const symbol_exprt &old_expr,
2626
const exprt &new_expr)
2727
{
28-
PRECONDITION(old_expr.type() == new_expr.type());
28+
PRECONDITION_WITH_DIAGNOSTICS(
29+
old_expr.type() == new_expr.type(),
30+
"types to be replaced should match.\nold type: '" +
31+
old_expr.type().pretty() + "'\nnew.type: '" + new_expr.type().pretty() +
32+
"')");
2933
expr_map.insert(std::pair<irep_idt, exprt>(
3034
old_expr.get_identifier(), new_expr));
3135
}
@@ -46,7 +50,8 @@ bool replace_symbolt::replace_symbol_expr(symbol_exprt &s) const
4650

4751
DATA_INVARIANT(
4852
s.type() == it->second.type(),
49-
"type of symbol to be replaced should match");
53+
"types to be replaced should match.\ns.type: '" + s.type().pretty() +
54+
"'\nit->second.type: '" + it->second.type().pretty() + "')");
5055
static_cast<exprt &>(s) = it->second;
5156

5257
return false;

0 commit comments

Comments
 (0)