diff --git a/test/libsolidity/semanticTests/functionTypes/packed_in_storage.sol b/test/libsolidity/semanticTests/functionTypes/packed_in_storage.sol new file mode 100644 index 000000000..7046658c1 --- /dev/null +++ b/test/libsolidity/semanticTests/functionTypes/packed_in_storage.sol @@ -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 diff --git a/test/libsolidity/semanticTests/functionTypes/packed_in_storage_internal.sol b/test/libsolidity/semanticTests/functionTypes/packed_in_storage_internal.sol new file mode 100644 index 000000000..b49666618 --- /dev/null +++ b/test/libsolidity/semanticTests/functionTypes/packed_in_storage_internal.sol @@ -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