Introduce address(...).code

This commit is contained in:
Alex Beregszaszi
2020-12-11 03:00:30 +00:00
parent 4b410b8731
commit 7b347b9ec2
10 changed files with 90 additions and 2 deletions
@@ -0,0 +1,22 @@
contract C {
bytes public initCode;
constructor() {
// This should catch problems, but lets also test the case the optimiser is buggy.
assert(address(this).code.length == 0);
initCode = address(this).code;
}
// To avoid dependency on exact length.
function f() public view returns (bool) { return address(this).code.length > 400; }
function g() public view returns (uint) { return address(0).code.length; }
function h() public view returns (uint) { return address(1).code.length; }
}
// ====
// compileViaYul: false
// ----
// constructor() ->
// initCode() -> 0x20, 0
// f() -> true
// g() -> 0
// h() -> 0
@@ -0,0 +1,19 @@
contract A {
constructor() {
assembly {
// This is only 7 bytes here.
mstore(0, 0x48aa5566000000)
return(0, 32)
}
}
}
contract C {
function f() public returns (bytes memory) { return address(new A()).code; }
function g() public returns (uint) { return address(new A()).code.length; }
}
// ====
// compileViaYul: false
// ----
// f() -> 0x20, 0x20, 0x48aa5566000000
// g() -> 0x20
@@ -0,0 +1,8 @@
contract C {
function f() public view returns (address) { return address(this); }
function g() public view returns (uint) { return f().balance; }
function h() public view returns (bytes memory) { return f().code; }
function i() public view returns (uint) { return f().code.length; }
function j() public view returns (uint) { return h().length; }
}
// ----
@@ -1,6 +1,6 @@
contract C {
function f() public returns (C) { return this; }
function g() public returns (uint) { return f().balance(); }
function g() public returns (uint) { return f().balance; }
}
// ----
// TypeError 3125: (114-125): Member "balance" not found or not visible after argument-dependent lookup in contract C. Use "address(...).balance" to access this address member.