mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7849 from ethereum/smt_constructor_local_vars
[SMTChecker] Fix constructors with local vars
This commit is contained in:
commit
2f6e006ea4
@ -215,9 +215,11 @@ void CHC::endVisit(FunctionDefinition const& _function)
|
|||||||
// This is done in endVisit(ContractDefinition).
|
// This is done in endVisit(ContractDefinition).
|
||||||
if (_function.isConstructor())
|
if (_function.isConstructor())
|
||||||
{
|
{
|
||||||
auto constructorExit = createBlock(&_function, "exit_");
|
auto constructorExit = createSymbolicBlock(interfaceSort(), "constructor_exit_" + to_string(_function.id()));
|
||||||
connectBlocks(m_currentBlock, predicate(*constructorExit));
|
connectBlocks(m_currentBlock, predicate(*constructorExit, currentStateVariables()));
|
||||||
setCurrentBlock(*constructorExit);
|
clearIndices(m_currentContract, m_currentFunction);
|
||||||
|
auto stateExprs = currentStateVariables();
|
||||||
|
setCurrentBlock(*constructorExit, &stateExprs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
pragma experimental SMTChecker;
|
||||||
|
contract F {
|
||||||
|
uint a;
|
||||||
|
constructor() public {
|
||||||
|
uint f = 2;
|
||||||
|
a = f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract E is F {}
|
||||||
|
contract D is E {
|
||||||
|
constructor() public {
|
||||||
|
uint d = 3;
|
||||||
|
a = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contract C is D {}
|
||||||
|
contract B is C {
|
||||||
|
constructor() public {
|
||||||
|
uint b = 4;
|
||||||
|
a = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract A is B {
|
||||||
|
constructor(uint x) public {
|
||||||
|
uint a1 = 4;
|
||||||
|
uint a2 = 5;
|
||||||
|
assert(a == a1);
|
||||||
|
assert(a == a2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (317-323): Unused function parameter. Remove or comment out the variable name to silence this warning.
|
||||||
|
// Warning: (385-400): Assertion violation happens here
|
@ -0,0 +1,13 @@
|
|||||||
|
pragma experimental SMTChecker;
|
||||||
|
contract C {
|
||||||
|
function f() public pure {}
|
||||||
|
constructor() public {
|
||||||
|
C c = this;
|
||||||
|
c.f(); // this does not warn now, but should warn in the future
|
||||||
|
this.f();
|
||||||
|
(this).f();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (204-208): "this" used in constructor. Note that external functions of a contract cannot be called while it is being constructed.
|
||||||
|
// Warning: (223-227): "this" used in constructor. Note that external functions of a contract cannot be called while it is being constructed.
|
Loading…
Reference in New Issue
Block a user