mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'origin/develop' into breaking
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
contract CalldataTest {
|
||||
function test(bytes calldata x) public returns (bytes calldata) {
|
||||
return x;
|
||||
}
|
||||
function tester(bytes calldata x) public returns (byte) {
|
||||
return this.test(x)[2];
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// tester(bytes): 0x20, 0x08, "abcdefgh" -> "c"
|
||||
@@ -0,0 +1,17 @@
|
||||
contract C {
|
||||
struct S {
|
||||
uint a;
|
||||
bytes b;
|
||||
mapping(uint => uint) c;
|
||||
uint[] d;
|
||||
}
|
||||
uint shifter;
|
||||
S public s;
|
||||
constructor() public {
|
||||
s.a = 7;
|
||||
s.b = "abc";
|
||||
s.c[0] = 9;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// s() -> 0x07, 0x40, 0x03, 0x6162630000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,17 @@
|
||||
library D {
|
||||
function f(bytes calldata _x) internal pure returns (bytes calldata) {
|
||||
return _x;
|
||||
}
|
||||
function g(bytes calldata _x) internal pure returns (bytes memory) {
|
||||
return _x;
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using D for bytes;
|
||||
function f(bytes calldata _x) public pure returns (byte, byte) {
|
||||
return (_x.f()[0], _x.g()[0]);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f(bytes): 0x20, 4, "abcd" -> 0x6100000000000000000000000000000000000000000000000000000000000000, 0x6100000000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,20 @@
|
||||
library D {
|
||||
function f(bytes calldata _x) public pure returns (bytes calldata) {
|
||||
return _x;
|
||||
}
|
||||
function g(bytes calldata _x) public pure returns (bytes memory) {
|
||||
return _x;
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using D for bytes;
|
||||
function f(bytes calldata _x) public pure returns (byte, byte) {
|
||||
return (_x.f()[0], _x.g()[0]);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >homestead
|
||||
// ----
|
||||
// library: D
|
||||
// f(bytes): 0x20, 4, "abcd" -> 0x6100000000000000000000000000000000000000000000000000000000000000, 0x6100000000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,17 @@
|
||||
library D {
|
||||
function f(bytes calldata _x) internal pure returns (byte) {
|
||||
return _x[0];
|
||||
}
|
||||
function g(bytes memory _x) internal pure returns (byte) {
|
||||
return _x[0];
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using D for bytes;
|
||||
function f(bytes calldata _x) public pure returns (byte, byte) {
|
||||
return (_x.f(), _x.g());
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f(bytes): 0x20, 4, "abcd" -> 0x6100000000000000000000000000000000000000000000000000000000000000, 0x6100000000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,20 @@
|
||||
library D {
|
||||
function f(bytes calldata _x) public pure returns (byte) {
|
||||
return _x[0];
|
||||
}
|
||||
function g(bytes memory _x) public pure returns (byte) {
|
||||
return _x[0];
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using D for bytes;
|
||||
function f(bytes calldata _x) public pure returns (byte, byte) {
|
||||
return (_x.f(), _x.g());
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >homestead
|
||||
// ----
|
||||
// library: D
|
||||
// f(bytes): 0x20, 4, "abcd" -> 0x6100000000000000000000000000000000000000000000000000000000000000, 0x6100000000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,25 @@
|
||||
struct Struct { uint x; }
|
||||
|
||||
library L {
|
||||
function f(Struct storage _x) internal view returns (uint256) {
|
||||
return _x.x;
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using L for Struct;
|
||||
|
||||
Struct s;
|
||||
|
||||
function h(Struct storage _s) internal view returns (uint) {
|
||||
// _s is pointer
|
||||
return _s.f();
|
||||
}
|
||||
function g() public returns (uint, uint) {
|
||||
s.x = 7;
|
||||
// s is reference
|
||||
return (s.f(), h(s));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// g() -> 7, 7
|
||||
@@ -0,0 +1,21 @@
|
||||
contract C {
|
||||
struct S {
|
||||
uint256 a;
|
||||
uint256 b;
|
||||
}
|
||||
|
||||
function f() public pure returns (uint256 a, uint256 b){
|
||||
assembly {
|
||||
// Make free memory dirty to check that the struct allocation cleans it up again.
|
||||
let freeMem := mload(0x40)
|
||||
mstore(freeMem, 42)
|
||||
mstore(add(freeMem, 32), 42)
|
||||
}
|
||||
S memory s;
|
||||
return (s.a, s.b);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0, 0
|
||||
@@ -0,0 +1,39 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
uint a;
|
||||
uint[] b;
|
||||
uint c;
|
||||
}
|
||||
|
||||
S s;
|
||||
constructor() public {
|
||||
s.a = 42;
|
||||
s.b.push(1);
|
||||
s.b.push(2);
|
||||
s.b.push(3);
|
||||
s.c = 21;
|
||||
}
|
||||
|
||||
function f(S memory m) public pure returns (uint, uint[] memory, uint) {
|
||||
return (m.a, m.b, m.c);
|
||||
}
|
||||
function g(S calldata c) external pure returns (uint, uint, uint, uint, uint, uint) {
|
||||
return (c.a, c.b.length, c.c, c.b[0], c.b[1], c.b[2]);
|
||||
}
|
||||
function g2(S calldata c1, S calldata c2) external pure returns (uint, uint, uint, uint, uint, uint) {
|
||||
return (c1.a, c1.c, c2.a, c2.b.length, c2.c, c2.b[0]);
|
||||
}
|
||||
function h() external view returns (uint, uint, uint, uint, uint, uint) {
|
||||
return (s.a, s.b.length, s.c, s.b[0], s.b[1], s.b[2]);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >homestead
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f((uint256,uint256[],uint256)): 0x20, 42, 0x60, 21, 3, 1, 2, 3 -> 42, 0x60, 21, 3, 1, 2, 3
|
||||
// g((uint256,uint256[],uint256)): 0x20, 42, 0x60, 21, 3, 1, 2, 3 -> 42, 3, 21, 1, 2, 3
|
||||
// g2((uint256,uint256[],uint256),(uint256,uint256[],uint256)): 0x40, 0x0120, 42, 0x60, 21, 2, 1, 2, 3, 7, 0x80, 9, 0, 1, 17 -> 42, 21, 7, 1, 9, 17
|
||||
// h() -> 42, 3, 21, 1, 2, 3
|
||||
Reference in New Issue
Block a user