Skip to content

Commit f37bb2e

Browse files
committed
Additional test coverage for named parameters
1 parent e73f5bd commit f37bb2e

13 files changed

Lines changed: 185 additions & 6 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
contract C {
2+
event E(uint256 a, uint256 b, string c);
3+
4+
function trigger() public {
5+
emit E(2, 7, "event");
6+
emit E({b: 7, a: 2, c: "event"});
7+
emit E({a: 2, c: "event", b: 7});
8+
emit E({c: "event", a: 2, b: 7});
9+
emit E({a: 2, b: 7, c: "event"});
10+
}
11+
}
12+
// ----
13+
// trigger() ->
14+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
15+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
16+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
17+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
18+
// ~ emit E(uint256,uint256,string): 0x02, 0x07, 0x60, 0x05, "event"
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
contract test {
2-
function a(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; }
3-
function b() public returns (uint r) { r = a({a: 1, b: 2, c: 3}); }
4-
function c() public returns (uint r) { r = a({b: 2, c: 3, a: 1}); }
1+
contract C {
2+
function internalFunction(uint a, uint b, uint c) internal returns (uint r) { r = a * 100 + b * 10 + c * 1; }
3+
function publicFunction(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; }
4+
function externalFunction(uint a, uint b, uint c) public returns (uint r) { r = a * 100 + b * 10 + c * 1; }
5+
6+
function internalOrdered() public returns (uint r) { r = internalFunction({a: 1, b: 2, c: 3}); }
7+
function internalUnordered() public returns (uint r) { r = internalFunction({b: 2, c: 3, a: 1}); }
8+
function publicOrdered() public returns (uint r) { r = publicFunction({a: 1, b: 2, c: 3}); }
9+
function publicUnordered() public returns (uint r) { r = publicFunction({b: 2, c: 3, a: 1}); }
10+
function externalOrdered() public returns (uint r) { r = externalFunction({a: 1, b: 2, c: 3}); }
11+
function externalUnordered() public returns (uint r) { r = publicFunction({b: 2, c: 3, a: 1}); }
512
}
613
// ----
7-
// b() -> 123
8-
// c() -> 123
14+
// internalOrdered() -> 123
15+
// internalUnordered() -> 123
16+
// publicOrdered() -> 123
17+
// publicUnordered() -> 123
18+
// externalOrdered() -> 123
19+
// externalUnordered() -> 123
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
contract A {
2+
function f(uint256 a, uint256 b, uint256 c) internal virtual returns (uint256) {
3+
return 1 * a + 2 * b + 3 * c;
4+
}
5+
}
6+
7+
contract B is A {
8+
function f(uint256 b, uint256 a, uint256 c) internal override returns (uint256) {
9+
return 0;
10+
}
11+
function baseOrdered() public returns (uint256) {
12+
return A.f({a: 1, b: 2, c: 3});
13+
}
14+
function baseUnordered() public returns (uint256) {
15+
return A.f({c: 3, a: 1, b: 2});
16+
}
17+
}
18+
// ----
19+
// baseOrdered() -> 14
20+
// baseUnordered() -> 14
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library L {
2+
function fi(uint256 a, uint256 b, uint256 c) internal returns (uint256) {
3+
return 1 * a + 2 * b + 3 * c;
4+
}
5+
function fe(uint256 a, uint256 b, uint256 c) external returns (uint256) {
6+
return 1 * a + 2 * b + 3 * c;
7+
}
8+
}
9+
10+
contract C {
11+
function internalOrdered() public returns (uint256) {
12+
return L.fi({a: 1, b: 2, c:3});
13+
}
14+
function internalUnordered() public returns (uint256) {
15+
return L.fi({c: 3, a: 1, b: 2});
16+
}
17+
function externalOrdered() external returns (uint256) {
18+
return L.fe({a: 1, b: 2, c:3});
19+
}
20+
function externalUnordered() public returns (uint256) {
21+
return L.fe({c: 3, a: 1, b: 2});
22+
}
23+
}
24+
// ----
25+
// library: L
26+
// internalOrdered() -> 14
27+
// internalUnordered() -> 14
28+
// externalOrdered() -> 14
29+
// externalUnordered() -> 14
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
library L {
2+
function multiply(uint256 self, uint256 x, uint256 y) internal pure returns (uint256, uint256) {
3+
return (self * x, self * y);
4+
}
5+
}
6+
7+
contract C {
8+
using L for uint256;
9+
10+
function ordered() external pure returns (uint256, uint256) {
11+
uint256 value = 1;
12+
return value.multiply({x: 2, y: 7});
13+
}
14+
function unordered() external pure returns (uint256, uint256) {
15+
uint256 value = 1;
16+
return value.multiply({y: 7, x: 2});
17+
}
18+
}
19+
// ----
20+
// ordered() -> 2, 7
21+
// unordered() -> 2, 7
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
contract C {
2+
function f() public pure returns (bytes memory) {
3+
return abi.encode({x: uint256(1), y: address(0)});
4+
}
5+
}
6+
7+
// ----
8+
// TypeError 2627: (82-124): Named arguments cannot be used for functions that take arbitrary parameters.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
contract C {
2+
uint[] public myArray;
3+
4+
function get(uint256 _index) public view returns (uint256) {
5+
return this.myArray({index: _index});
6+
}
7+
}
8+
// ----
9+
// TypeError 4974: (121-150): Named argument "index" does not match function declaration.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
contract B {
2+
uint256 public x;
3+
uint256 public y;
4+
constructor(uint _x, uint _y) { x = _x; y = _y; }
5+
}
6+
7+
contract C is B {
8+
constructor() B({y: 2, x: 1}) {}
9+
}
10+
11+
// ----
12+
// ParserError 6933: (152-153): Expected primary expression.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
contract C {
2+
function f(address target) public returns (bool success, bytes memory data) {
3+
(success, data) = target.call({data: ""});
4+
}
5+
}
6+
// ====
7+
// EVMVersion: >=byzantium
8+
// ----
9+
// TypeError 4974: (121-144): Named argument "data" does not match function declaration.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
contract C {
2+
function add(uint x, uint y) public pure returns (uint) { return x + y; }
3+
4+
function callViaFunctionPointer() public pure returns (uint) {
5+
function(uint, uint) pure returns (uint) fp = add;
6+
return fp({y: 2, x: 1});
7+
}
8+
}
9+
10+
// ----
11+
// TypeError 4974: (233-249): Named argument "y" does not match function declaration.
12+
// TypeError 4974: (233-249): Named argument "x" does not match function declaration.

0 commit comments

Comments
 (0)