2020-11-23 18:06:44 +00:00
|
|
|
pragma abicoder v2;
|
2019-11-14 14:43:02 +00:00
|
|
|
library L {
|
|
|
|
struct S { uint256 a; }
|
|
|
|
function f(S storage s) external returns (uint) { return s.a; }
|
|
|
|
function g(S memory m) public returns (uint) { return m.a; }
|
|
|
|
}
|
|
|
|
contract C {
|
|
|
|
L.S s;
|
2020-06-23 12:14:24 +00:00
|
|
|
constructor() { s.a = 42; }
|
2019-11-14 14:43:02 +00:00
|
|
|
|
|
|
|
function f() public returns (bool, bool, uint256) {
|
|
|
|
uint256 s_ptr;
|
2020-07-01 17:25:14 +00:00
|
|
|
assembly { s_ptr := s.slot }
|
2019-11-14 14:43:02 +00:00
|
|
|
(bool success, bytes memory data) = address(L).delegatecall(abi.encodeWithSelector(L.f.selector, s_ptr));
|
|
|
|
return (L.f.selector == bytes4(keccak256("f(L.S storage)")), success, abi.decode(data, (uint256)));
|
|
|
|
}
|
|
|
|
function g() public returns (bool, bool, uint256) {
|
|
|
|
(bool success, bytes memory data) = address(L).delegatecall(abi.encodeWithSelector(L.g.selector, L.S(23)));
|
|
|
|
return (L.g.selector == bytes4(keccak256("g(L.S)")), success, abi.decode(data, (uint256)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ====
|
2020-12-22 16:45:55 +00:00
|
|
|
// compileViaYul: also
|
2019-11-14 14:43:02 +00:00
|
|
|
// EVMVersion: >homestead
|
|
|
|
// ----
|
|
|
|
// library: L
|
|
|
|
// f() -> true, true, 42
|
|
|
|
// g() -> true, true, 23
|