Fix magic access

This commit is contained in:
Leo Alt 2021-09-27 16:55:59 +02:00
parent d25fb29178
commit d81ebe97c3
3 changed files with 50 additions and 27 deletions

View File

@ -7,6 +7,7 @@ Compiler Features:
Bugfixes:
* SMTChecker: Fix internal error in magic type access (``block``, ``msg``, ``tx``).

View File

@ -1316,7 +1316,15 @@ bool SMTEncoder::visit(MemberAccess const& _memberAccess)
solAssert(name == "block" || name == "msg" || name == "tx", "");
defineExpr(_memberAccess, state().txMember(name + "." + _memberAccess.memberName()));
}
else if (auto magicType = dynamic_cast<MagicType const*>(exprType); magicType->kind() == MagicType::Kind::MetaType)
else if (auto magicType = dynamic_cast<MagicType const*>(exprType))
{
if (magicType->kind() == MagicType::Kind::Block)
defineExpr(_memberAccess, state().txMember("block." + _memberAccess.memberName()));
else if (magicType->kind() == MagicType::Kind::Message)
defineExpr(_memberAccess, state().txMember("msg." + _memberAccess.memberName()));
else if (magicType->kind() == MagicType::Kind::Transaction)
defineExpr(_memberAccess, state().txMember("tx." + _memberAccess.memberName()));
else if (magicType->kind() == MagicType::Kind::MetaType)
{
auto const& memberName = _memberAccess.memberName();
if (memberName == "min" || memberName == "max")
@ -1339,9 +1347,11 @@ bool SMTEncoder::visit(MemberAccess const& _memberAccess)
_memberAccess.location(),
"Assertion checker does not yet support this expression."
);
}
}
else
solUnimplementedAssert(false, "");
solAssert(false, "");
return false;
}
@ -1419,7 +1429,7 @@ bool SMTEncoder::visit(MemberAccess const& _memberAccess)
return false;
}
}
else
m_errorReporter.warning(
7650_error,
_memberAccess.location(),

View File

@ -0,0 +1,12 @@
contract C {
function f() public payable {
assert((msg).value == 10);
assert((true ? msg : msg).value == 12);
}
}
// ====
// SMTEngine: all
// SMTIgnoreOS: macos
// ----
// Warning 6328: (46-71): CHC: Assertion violation happens here.\nCounterexample:\n\n\nTransaction trace:\nC.constructor()\nC.f(){ value: 11 }
// Warning 6328: (75-113): CHC: Assertion violation happens here.\nCounterexample:\n\n\nTransaction trace:\nC.constructor()\nC.f()