Allow using calldata keyword to specify data location

This commit is contained in:
mingchuan
2018-05-30 18:05:55 +08:00
parent 9d5064d04d
commit b7cafcbdf9
25 changed files with 155 additions and 25 deletions
@@ -0,0 +1,4 @@
contract test {
function f(bytes calldata) external;
}
// ----
@@ -0,0 +1,5 @@
contract test {
function f(bytes memory) external;
}
// ----
// TypeError: (31-36): Location has to be calldata for external functions (remove the "memory" or "storage" keyword).
@@ -0,0 +1,5 @@
contract test {
function f(bytes storage) external;
}
// ----
// TypeError: (31-36): Location has to be calldata for external functions (remove the "memory" or "storage" keyword).
@@ -0,0 +1,5 @@
library test {
function f(bytes calldata) public;
}
// ----
// TypeError: (30-35): Location cannot be calldata for non-external functions (remove the "calldata" keyword).
@@ -0,0 +1,5 @@
contract test {
function f(bytes4 memory) public;
}
// ----
// TypeError: (31-37): Data location can only be given for array or struct types.
@@ -0,0 +1,5 @@
contract test {
function f(bytes calldata) internal;
}
// ----
// TypeError: (31-36): Variable cannot be declared as "calldata" (remove the "calldata" keyword).
@@ -0,0 +1,4 @@
contract test {
function f(bytes memory) internal;
}
// ----
@@ -0,0 +1,4 @@
contract test {
function f(bytes storage) internal;
}
// ----
@@ -0,0 +1,5 @@
contract test {
function f(bytes calldata) public;
}
// ----
// TypeError: (31-36): Location has to be memory for publicly visible functions (remove the "storage" or "calldata" keyword).
@@ -0,0 +1,4 @@
contract test {
function f(bytes memory) public;
}
// ----
@@ -0,0 +1,5 @@
contract test {
function f(bytes storage) public;
}
// ----
// TypeError: (31-36): Location has to be memory for publicly visible functions (remove the "storage" or "calldata" keyword).
@@ -0,0 +1,13 @@
contract test {
function f() {
uint storage a1;
bytes16 storage b1;
uint memory a2;
bytes16 memory b2;
}
}
// ----
// TypeError: (41-56): Data location can only be given for array or struct types.
// TypeError: (64-82): Data location can only be given for array or struct types.
// TypeError: (90-104): Data location can only be given for array or struct types.
// TypeError: (112-129): Data location can only be given for array or struct types.
@@ -0,0 +1,14 @@
contract test {
uint[] a;
uint[] b;
function f() public {
uint[] storage s1 = a;
uint[] memory s2 = new uint[](42);
uint[] s3 = b;
s1.push(42);
s2[3] = 12;
s3.push(42);
}
}
// ----
// Warning: (147-156): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
@@ -2,4 +2,4 @@ contract Foo {
function f(uint[] storage constant x, uint[] memory y) internal { }
}
// ----
// TypeError: (30-55): Storage location has to be "memory" (or unspecified) for constants.
// TypeError: (30-55): Data location has to be "memory" (or unspecified) for constants.