mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Added tests for function type that would be packed in storage
This commit is contained in:
parent
ee0e3e9377
commit
787e536b61
@ -0,0 +1,25 @@
|
||||
contract C {
|
||||
uint8 public a = 20;
|
||||
function() external public f = this.g;
|
||||
function g() external {
|
||||
}
|
||||
function slots() public returns (uint _a, uint _f) {
|
||||
assembly {
|
||||
_a := a.slot
|
||||
_f := f.slot
|
||||
}
|
||||
}
|
||||
function offsets() public returns (uint _a, uint _f) {
|
||||
assembly {
|
||||
_a := a.offset
|
||||
_f := f.offset
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// a() -> 0x14
|
||||
// f() -> 7175878113405833249322534082293024008058894263831758935649259662147697246208
|
||||
// slots() -> 0, 0
|
||||
// offsets() -> 0, 1
|
@ -0,0 +1,40 @@
|
||||
contract C {
|
||||
function() internal f = g;
|
||||
uint8 public a = 20;
|
||||
|
||||
function g() internal {
|
||||
}
|
||||
function slots() public returns (uint _a, uint _f) {
|
||||
assembly {
|
||||
_a := a.slot
|
||||
_f := f.slot
|
||||
}
|
||||
}
|
||||
function offsets() public returns (uint _a, uint _f) {
|
||||
assembly {
|
||||
_a := a.offset
|
||||
_f := f.offset
|
||||
}
|
||||
}
|
||||
function delete_a() external {
|
||||
delete a;
|
||||
}
|
||||
// The actual value cannot be returned since it would be different for various settings
|
||||
// (optimized v/s non-optimized, legacy v/s IR).
|
||||
function test_f_non_zero() external returns (bool) {
|
||||
uint storage_value;
|
||||
assembly {
|
||||
storage_value := sload(f.slot)
|
||||
}
|
||||
assert(storage_value != 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// a() -> 0x14
|
||||
// slots() -> 0, 0
|
||||
// offsets() -> 8, 0
|
||||
// delete_a() ->
|
||||
// test_f_non_zero() -> true
|
Loading…
Reference in New Issue
Block a user