Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added tests for default data location for parameters. Fixed older tes…
…ts to use explicit storage parameters to silence warnings.
  • Loading branch information
chase1745 committed Jul 8, 2018
commit dbd3cbce02969b1d429d5f83ec9266e610a22d43
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// The constructor of a base class should not be visible in the derived class
contract A { constructor(string) public { } }
contract A { constructor(string memory) public { } }
contract B is A {
function f() pure public {
A x = A(0); // convert from address
Expand All @@ -9,4 +9,4 @@ contract B is A {
}
}
// ----
// TypeError: (243-247): Explicit type conversion not allowed from "string memory" to "contract A".
// TypeError: (250-254): Explicit type conversion not allowed from "string memory" to "contract A".
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// The constructor of a base class should not be visible in the derived class
contract A { function A(string s) public { } }
contract A { function A(string memory s) public { } }
contract B is A {
function f() pure public {
A x = A(0); // convert from address
Expand All @@ -9,5 +9,5 @@ contract B is A {
}
}
// ----
// Warning: (91-122): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
// TypeError: (244-248): Explicit type conversion not allowed from "string memory" to "contract A".
// Warning: (91-129): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
// TypeError: (251-255): Explicit type conversion not allowed from "string memory" to "contract A".
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
contract C {
struct S { bool f; }
S s;
function f() internal view returns (S c) {
function f() internal view returns (S memory c) {
c = s;
}
function g() internal view returns (S) {
function g() internal view returns (S memory) {
return s;
}
function h() internal pure returns (S) {
function h() internal pure returns (S memory) {
}
function i(bool flag) internal view returns (S c) {
function i(bool flag) internal view returns (S memory c) {
if (flag) c = s;
}
function j(bool flag) internal view returns (S) {
function j(bool flag) internal view returns (S memory) {
if (flag) return s;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
function i() external pure returns(uint[]) {}
}
// ----
// TypeError: (52-58): Location must be specified as "memory" for parameters in publicly visible functions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract C {
// Warning for no data location provided can be silenced with storage or memory.
function f(uint[] memory, uint[] storage) private pure {}
function g(uint[] memory, uint[] storage) internal pure {}
function h(uint[] memory) public pure {}
// No warning on external functions, because of default to calldata.
function i(uint[]) external pure {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract C {
// Shows that the warning for no data location provided can be silenced with storage or memory.
function f() private pure returns(uint[] memory, uint[] storage) {}
function g() internal pure returns(uint[] memory, uint[] storage) {}
function h() public pure returns(uint[] memory) {}
function i() external pure returns(uint[] memory) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
function g(uint[]) internal pure {}
}
// ----
// TypeError: (28-34): Location must be specified as either "memory" or "storage" for parameters.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
function g() internal pure returns(uint[]) {}
}
// ----
// TypeError: (52-58): Location must be specified as either "memory" or "storage" for parameters.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
library L {
// Warning for no data location provided can be silenced with storage or memory.
function f(uint[] memory, uint[] storage) private pure {}
function g(uint[] memory, uint[] storage) internal pure {}
function h(uint[] memory) public pure {}
// No warning on external functions, because of default to calldata.
function i(uint[]) external pure {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library L {
function g(uint[]) internal pure {}
}
// ----
// TypeError: (27-33): Location must be specified as either "memory" or "storage" for parameters.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
library L {
function f(uint[]) private pure {}
function g(uint[]) internal pure {}
function h(uint[]) public pure {}
}
// ----
// TypeError: (27-33): Location must be specified as either "memory" or "storage" for parameters.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library L {
function h(uint[]) public pure {}
}
// ----
// TypeError: (27-33): Location must be specified as "memory" for parameters in publicly visible functions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract C {
function f(uint[]) private pure {}
function g(uint[]) internal pure {}
function h(uint[]) public pure {}
}
// ----
// TypeError: (28-34): Location must be specified as either "memory" or "storage" for parameters.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
function f() private pure returns(uint[]) {}
}
// ----
// TypeError: (51-57): Location must be specified as either "memory" or "storage" for parameters.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
function h(uint[]) public pure {}
}
// ----
// TypeError: (28-34): Location must be specified as "memory" for parameters in publicly visible functions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
function h() public pure returns(uint[]) {}
}
// ----
// TypeError: (50-56): Location must be specified as "memory" for parameters in publicly visible functions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pragma experimental ABIEncoderV2;
contract C {
struct S1 { int i; }
struct S2 { int i; }
function f(S1) pure {}
function f(S2) pure {}
function f(S1 memory) pure {}
function f(S2 memory) pure {}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
// TypeError: (129-151): Function overload clash during conversion to external types for arguments.
// TypeError: (136-165): Function overload clash during conversion to external types for arguments.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma experimental ABIEncoderV2;
contract C {
struct S1 { function() external a; }
struct S2 { bytes24 a; }
function f(S1) public pure {}
function f(S2) public pure {}
function f(S1 memory) public pure {}
function f(S2 memory) public pure {}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma experimental ABIEncoderV2;

contract C {
struct S { function() internal a; }
function f(S) {}
function f(S memory) {}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma experimental ABIEncoderV2;

contract C {
struct S { mapping(uint => uint) a; }
function f(S) {}
function f(S memory) {}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma experimental ABIEncoderV2;
contract C {
struct T { mapping(uint => uint) a; }
struct S { T[][2] b; }
function f(S) {}
function f(S memory) {}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma experimental ABIEncoderV2;

contract C {
function f() public pure returns (string[][]) {}
function f() public pure returns (string[][] memory) {}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
contract C {
function f() public pure returns (string[][]) {}
function f() public pure returns (string[][] memory) {}
}
// ----
// TypeError: (51-61): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
contract C {
function f() public pure returns (uint[][2]) {}
function f() public pure returns (uint[][2] memory) {}
}
// ----
// TypeError: (51-60): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma experimental ABIEncoderV2;

contract C {
struct S { string[] s; }
function f() public pure returns (S) {}
function f() public pure returns (S memory) {}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract C {
struct S { string[] s; }
function f() public pure returns (S x) {}
function f() public pure returns (S memory x) {}
}
// ----
// TypeError: (80-83): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature.
// TypeError: (80-90): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
contract test {
function f(uint[] constant a) public { }
function f(uint[] memory constant a) public { }
}
// ----
// TypeError: (31-48): Illegal use of "constant" specifier.
// TypeError: (31-48): Constants of non-value type not yet implemented.
// TypeError: (31-48): Uninitialized "constant" variable.
// TypeError: (31-55): Illegal use of "constant" specifier.
// TypeError: (31-55): Constants of non-value type not yet implemented.
// TypeError: (31-55): Uninitialized "constant" variable.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
contract C {
uint[] data;
function f(uint[] x) public {
function f(uint[] memory x) public {
uint[] storage dataRef = data;
dataRef = x;
}
}
// ----
// TypeError: (121-122): Type uint256[] memory is not implicitly convertible to expected type uint256[] storage pointer.
// TypeError: (128-129): Type uint256[] memory is not implicitly convertible to expected type uint256[] storage pointer.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract C {
uint[] data;
function f(uint[] x) public {
function f(uint[] memory x) public {
data = x;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
contract C {
function f(uint[] storage x) private {
}
function g(uint[] x) public {
function g(uint[] memory x) public {
f(x);
}
}
// ----
// TypeError: (106-107): Invalid type for argument in function call. Invalid implicit conversion from uint256[] memory to uint256[] storage pointer requested.
// TypeError: (113-114): Invalid type for argument in function call. Invalid implicit conversion from uint256[] memory to uint256[] storage pointer requested.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ contract C {
function f(uint[] storage x) private {
g(x);
}
function g(uint[] x) public {
function g(uint[] memory x) public {
}
}
// ----
// Warning: (91-99): Unused function parameter. Remove or comment out the variable name to silence this warning.
// Warning: (80-115): Function state mutability can be restricted to pure
// Warning: (91-106): Unused function parameter. Remove or comment out the variable name to silence this warning.
// Warning: (80-122): Function state mutability can be restricted to pure
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ contract Test {
string s;
bytes b;
function h(string _s) external { bytes(_s).length; }
function i(string _s) internal { bytes(_s).length; }
function i(string memory _s) internal { bytes(_s).length; }
function j() internal { bytes(s).length; }
function k(bytes _b) external { string(_b); }
function l(bytes _b) internal { string(_b); }
function l(bytes memory _b) internal { string(_b); }
function m() internal { string(b); }
}
// ----
// Warning: (47-99): Function state mutability can be restricted to pure
// Warning: (104-156): Function state mutability can be restricted to pure
// Warning: (161-203): Function state mutability can be restricted to view
// Warning: (208-253): Function state mutability can be restricted to pure
// Warning: (258-303): Function state mutability can be restricted to pure
// Warning: (308-344): Function state mutability can be restricted to view
// Warning: (104-163): Function state mutability can be restricted to pure
// Warning: (168-210): Function state mutability can be restricted to view
// Warning: (215-260): Function state mutability can be restricted to pure
// Warning: (265-317): Function state mutability can be restricted to pure
// Warning: (322-358): Function state mutability can be restricted to view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pragma experimental ABIEncoderV2;
library c {
struct S { uint x; }
function f() public returns (S ) {}
function f() public returns (S memory) {}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
// Warning: (75-110): Function state mutability can be restricted to pure
// Warning: (75-116): Function state mutability can be restricted to pure
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
contract M {
function f(uint[]) public;
function f(int[]) public;
function f(uint[] memory) public;
function f(int[] memory) public;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
contract C {
function f() public returns (string) {
function f() public returns (string memory) {
string memory x = "Hello";
string memory y = "World";
string[2] memory z = [x, y];
return (z[0]);
}
}
// ----
// Warning: (17-191): Function state mutability can be restricted to pure
// Warning: (17-198): Function state mutability can be restricted to pure
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
contract C {
function f() public returns (string) {
function f() public returns (string memory) {
string[2] memory z = ["Hello", "World"];
return (z[0]);
}
}
// ----
// Warning: (17-133): Function state mutability can be restricted to pure
// Warning: (17-140): Function state mutability can be restricted to pure
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
contract C {
function f() public returns (string) {
function f() public returns (string memory) {
return (["foo", "man", "choo"][1]);
}
}
// ----
// Warning: (17-105): Function state mutability can be restricted to pure
// Warning: (17-112): Function state mutability can be restricted to pure
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pragma experimental ABIEncoderV2;
contract C {
struct S { uint a; T[] sub; }
struct T { uint[] x; }
function f() public returns (uint, S) {
function f() public returns (uint, S memory) {
}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
// Warning: (112-157): Function state mutability can be restricted to pure
// Warning: (112-164): Function state mutability can be restricted to pure
Loading