[SMTChecker] Support named arguments in function calls

This commit is contained in:
Leonardo Alt
2020-11-20 11:52:26 -01:00
parent 8d315ee130
commit e4339b0526
12 changed files with 120 additions and 41 deletions
@@ -1,8 +1,10 @@
contract test {
function a(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; }
function b() public returns (uint r) { r = a({a: 1, b: 2, c: 3}); }
function c() public returns (uint r) { r = a({b: 2, c: 3, a: 1}); }
}
// ====
// compileViaYul: also
// ----
// b() -> 123
// c() -> 123
@@ -20,6 +20,8 @@ contract C {
return f({b: 1, a: 2});
if (num == 3)
return f({c: 1, a: 2, b: 3});
if (num == 4)
return f({b: 5, c: 1, a: 2});
return 500;
}
@@ -31,4 +33,5 @@ contract C {
// call(uint256): 1 -> 1
// call(uint256): 2 -> 3
// call(uint256): 3 -> 6
// call(uint256): 4 -> 500
// call(uint256): 4 -> 8
// call(uint256): 5 -> 500
@@ -6,7 +6,7 @@ contract C {
S public s;
constructor() {
s = S({a: 1, x: true});
s = S({x: true, a: 1});
}
}
@@ -0,0 +1,34 @@
pragma experimental SMTChecker;
library L {
function l(uint x, uint y) internal pure returns (uint) {
return x + y;
}
}
contract C {
function f(uint u, uint s, bool b) internal pure returns (uint z) {
if (b)
z = u;
else
z = s;
}
using L for uint;
function call() public pure {
uint a = 2;
uint b = a.l({y: 3});
assert(b == 5);
b = L.l({x: 3, y: 3});
assert(b == 6);
b = f({b: true, u: 1, s: 2});
assert(b == 1);
b = f({b: false, u: 1, s: 2});
// Fails, should be 2.
assert(b == 6);
}
}
// ----
// Warning 8364: (360-361): Assertion checker does not yet implement type type(library L)
// Warning 6328: (507-521): CHC: Assertion violation happens here.
// Warning 8364: (360-361): Assertion checker does not yet implement type type(library L)
@@ -0,0 +1,14 @@
pragma experimental SMTChecker;
contract C {
function f(uint u, string memory s, bool b) internal {}
function call() public {
f({s: "abc", u: 1, b: true});
f({s: "abc", b: true, u: 1});
f({u: 1, s: "abc", b: true});
f({b: true, s: "abc", u: 1});
f({u: 1, b: true, s: "abc"});
f({b: true, u: 1, s: "abc"});
}
}
// ----
@@ -0,0 +1,15 @@
pragma experimental SMTChecker;
contract C {
function f(uint u, string memory s, bool b) internal {}
function f(uint u, uint s, uint b) internal {}
function call() public {
f({s: "abc", u: 1, b: true});
f({s: "abc", b: true, u: 1});
f({u: 1, s: "abc", b: true});
f({b: true, s: "abc", u: 1});
f({u: 1, b: true, s: "abc"});
f({b: true, u: 1, s: "abc"});
}
}
// ----