Added tests for function type that would be packed in storage

This commit is contained in:
hrkrshnn 2021-09-28 15:28:22 +02:00
parent ee0e3e9377
commit 787e536b61
2 changed files with 65 additions and 0 deletions

View File

@ -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

View File

@ -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