Skip to content

Commit 8649e1e

Browse files
committed
Improve replace_symbolt precondition message
Invariant violations now print out the actual types that were mismatched.
1 parent 778fb97 commit 8649e1e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/util/replace_symbol.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ 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. old type:\n",
31+
old_expr.type().pretty(),
32+
"\nnew.type:\n",
33+
new_expr.type().pretty());
2934
expr_map.insert(std::pair<irep_idt, exprt>(
3035
old_expr.get_identifier(), new_expr));
3136
}
@@ -46,7 +51,10 @@ bool replace_symbolt::replace_symbol_expr(symbol_exprt &s) const
4651

4752
DATA_INVARIANT(
4853
s.type() == it->second.type(),
49-
"type of symbol to be replaced should match");
54+
"types to be replaced should match. s.type:\n",
55+
s.type().pretty(),
56+
"\nit->second.type:\n",
57+
it->second.type().pretty());
5058
static_cast<exprt &>(s) = it->second;
5159

5260
return false;

0 commit comments

Comments
 (0)