Merge pull request #10802 from ethereum/smt_fix_override

[SMTChecker] Fix static virtual resolution
This commit is contained in:
Leonardo 2021-01-18 17:10:31 +01:00 committed by GitHub
commit 51b7dc69b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 3 deletions

View File

@ -2643,15 +2643,24 @@ pair<FunctionDefinition const*, ContractDefinition const*> SMTEncoder::functionC
auto funDef = dynamic_cast<FunctionDefinition const*>(_ref->annotation().referencedDeclaration);
if (!funDef)
return {funDef, _contract};
auto contextContract = _contract;
if (lookup == VirtualLookup::Virtual)
ContractDefinition const* contextContract = nullptr;
switch (lookup)
{
case VirtualLookup::Virtual:
funDef = &funDef->resolveVirtual(*_contract);
else if (lookup == VirtualLookup::Super)
contextContract = _contract;
break;
case VirtualLookup::Super:
{
auto super = _contract->superContract(*_contract);
solAssert(super, "Super contract not available.");
funDef = &funDef->resolveVirtual(*_contract, super);
contextContract = super;
break;
}
case VirtualLookup::Static:
contextContract = funDef->annotation().contract;
break;
}
return {funDef, contextContract};
};

View File

@ -0,0 +1,21 @@
pragma experimental SMTChecker;
contract BaseBase {
uint x;
function init(uint a, uint b) public virtual {
x = a;
}
}
contract Base is BaseBase {
function init(uint a, uint b) public override {
}
}
contract Child is Base {
function bInit(uint c, uint d) public {
BaseBase.init(c, d);
assert(x == c);
assert(x == d); // should fail
}
}
// ----
// Warning 5667: (84-90): Unused function parameter. Remove or comment out the variable name to silence this warning.
// Warning 6328: (314-328): CHC: Assertion violation happens here.\nCounterexample:\nx = 0\nc = 0\nd = 1\n\nTransaction trace:\nChild.constructor()\nState: x = 0\nChild.bInit(0, 1)\n BaseBase.init(0, 1) -- internal call