Adding more tests for function types

This commit is contained in:
chriseth 2020-07-17 10:22:30 +02:00 committed by Djordje Mijovic
parent e7d5a7da10
commit a1da90d14b
7 changed files with 74 additions and 0 deletions

View File

@ -6,5 +6,7 @@ contract C {
return (false ? g : h)(2, 1); return (false ? g : h)(2, 1);
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// f() -> 1 // f() -> 1

View File

@ -0,0 +1,10 @@
contract C {
function f() external payable returns (uint) { assert(msg.value > 0); return 1; }
function g() external payable returns (uint) { assert(msg.value > 0); return 2; }
function h() public payable returns (uint) {
return [this.f, this.g][0]{value: 1}();
}
}
// ----
// h(), 1 ether -> 1

View File

@ -0,0 +1,9 @@
contract C {
function f() pure public {
function(uint a) returns (uint) x;
x({a:2});
}
}
// ----
// Warning 6162: (61-67): Naming function type parameters is deprecated.
// TypeError 4974: (95-103): Named argument "a" does not match function declaration.

View File

@ -0,0 +1,13 @@
library L {
function f(uint a) internal pure {}
function g(uint a) internal pure {}
}
contract C {
using L for *;
function f() pure public {
uint t = 8;
[t.f, t.g][0]();
}
}
// ----
// TypeError 9563: (186-189): Invalid mobile type.

View File

@ -0,0 +1,13 @@
library L {
function f(uint a) internal pure {}
}
contract C {
using L for *;
function f() pure public {
uint t;
function() pure x;
[t.f, x][0]({a: 8});
}
}
// ----
// TypeError 9563: (169-172): Invalid mobile type.

View File

@ -0,0 +1,13 @@
contract D {
function f(uint a) external payable {}
function g(uint a) external {}
}
contract C {
function f() public {
D d;
[d.f{value: 1}, d.g][0](8);
}
}
// ----
// TypeError 9563: (155-168): Invalid mobile type.

View File

@ -0,0 +1,14 @@
library L {
function f(uint a) internal pure {}
function g(uint a) internal pure {}
}
contract C {
using L for *;
function f(bool x) pure public {
uint t = 8;
(x ? t.f : t.g)();
}
}
// ----
// TypeError 9717: (196-199): Invalid mobile type in true expression.
// TypeError 3703: (202-205): Invalid mobile type in false expression.