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
Fixed older tests to use explicit "memory" data location to silence e…
…rrors.
  • Loading branch information
chase1745 committed Jul 8, 2018
commit c1623e6313cd01197f29b5b6548b29d7a9b46159
8 changes: 4 additions & 4 deletions docs/abi-spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ Given the contract:
pragma solidity ^0.4.16;

contract Foo {
function bar(bytes3[2]) public pure {}
function bar(bytes3[2] memory) public pure {}
function baz(uint32 x, bool y) public pure returns (bool r) { r = x > 32 || y; }
function sam(bytes, bool, uint[]) public pure {}
function sam(bytes memory, bool, uint[] memory) public pure {}
}


Expand Down Expand Up @@ -490,8 +490,8 @@ As an example, the code
contract Test {
struct S { uint a; uint[] b; T[] c; }
struct T { uint x; uint y; }
function f(S s, T t, uint a) public { }
function g() public returns (S s, T t, uint a) {}
function f(S memory s, T memory t, uint a) public { }
function g() public returns (S memory s, T memory t, uint a) {}
}

would result in the JSON:
Expand Down
8 changes: 4 additions & 4 deletions docs/assembly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ idea is that assembly libraries will be used to enhance the language in such way
pragma solidity ^0.4.0;

library GetCode {
function at(address _addr) public view returns (bytes o_code) {
function at(address _addr) public view returns (bytes memory o_code) {
assembly {
// retrieve the size of the code, this needs assembly
let size := extcodesize(_addr)
Expand Down Expand Up @@ -83,15 +83,15 @@ you really know what you are doing.
library VectorSum {
// This function is less efficient because the optimizer currently fails to
// remove the bounds checks in array access.
function sumSolidity(uint[] _data) public view returns (uint o_sum) {
function sumSolidity(uint[] memory _data) public view returns (uint o_sum) {
for (uint i = 0; i < _data.length; ++i)
o_sum += _data[i];
}

// We know that we only access the array in bounds, so we can avoid the check.
// 0x20 needs to be added to an array because the first slot contains the
// array length.
function sumAsm(uint[] _data) public view returns (uint o_sum) {
function sumAsm(uint[] memory _data) public view returns (uint o_sum) {
for (uint i = 0; i < _data.length; ++i) {
assembly {
o_sum := add(o_sum, mload(add(add(_data, 0x20), mul(i, 0x20))))
Expand All @@ -100,7 +100,7 @@ you really know what you are doing.
}

// Same as above, but accomplish the entire code within inline assembly.
function sumPureAsm(uint[] _data) public view returns (uint o_sum) {
function sumPureAsm(uint[] memory _data) public view returns (uint o_sum) {
assembly {
// Load the length (first 32 bytes)
let len := mload(_data)
Expand Down
6 changes: 3 additions & 3 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1287,12 +1287,12 @@ custom types without the overhead of external function calls:
uint[] limbs;
}

function fromUint(uint x) internal pure returns (bigint r) {
function fromUint(uint x) internal pure returns (bigint memory r) {
r.limbs = new uint[](1);
r.limbs[0] = x;
}

function add(bigint _a, bigint _b) internal pure returns (bigint r) {
function add(bigint memory _a, bigint memory _b) internal pure returns (bigint memory r) {
r.limbs = new uint[](max(_a.limbs.length, _b.limbs.length));
uint carry = 0;
for (uint i = 0; i < r.limbs.length; ++i) {
Expand All @@ -1315,7 +1315,7 @@ custom types without the overhead of external function calls:
}
}

function limb(bigint _a, uint _limb) internal pure returns (uint) {
function limb(bigint memory _a, uint _limb) internal pure returns (uint) {
return _limb < _a.limbs.length ? _a.limbs[_limb] : 0;
}

Expand Down
11 changes: 5 additions & 6 deletions docs/frequently-asked-questions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Example::
pragma solidity ^0.4.16;

contract C {
function f() public pure returns (uint8[5]) {
function f() public pure returns (uint8[5] memory) {
string[4] memory adaArr = ["This", "is", "an", "array"];
return ([1, 2, 3, 4, 5]);
}
Expand Down Expand Up @@ -479,7 +479,7 @@ independent copies will be created::
h(x);
}

function g(uint[20] y) internal pure {
function g(uint[20] memory y) internal pure {
y[2] = 3;
}

Expand All @@ -489,10 +489,9 @@ independent copies will be created::
}

The call to ``g(x)`` will not have an effect on ``x`` because it needs
to create an independent copy of the storage value in memory
(the default storage location is memory). On the other hand,
``h(x)`` successfully modifies ``x`` because only a reference
and not a copy is passed.
to create an independent copy of the storage value in memory.
On the other hand, ``h(x)`` successfully modifies ``x`` because only
a reference and not a copy is passed.

Sometimes, when I try to change the length of an array with ex: ``arrayname.length = 7;`` I get a compiler error ``Value must be an lvalue``. Why?
==================================================================================================================================================
Expand Down
8 changes: 4 additions & 4 deletions docs/solidity-by-example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ of votes.
Proposal[] public proposals;

/// Create a new ballot to choose one of `proposalNames`.
constructor(bytes32[] proposalNames) public {
constructor(bytes32[] memory proposalNames) public {
chairperson = msg.sender;
voters[chairperson].weight = 1;

Expand Down Expand Up @@ -452,9 +452,9 @@ high or low invalid bids.
/// correctly blinded invalid bids and for all bids except for
/// the totally highest.
function reveal(
uint[] _values,
bool[] _fake,
bytes32[] _secret
uint[] memory _values,
bool[] memory _fake,
bytes32[] memory _secret
)
public
onlyAfter(biddingEnd)
Expand Down
20 changes: 10 additions & 10 deletions docs/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,11 @@ Another example that uses external function types::
}
Request[] requests;
event NewRequest(uint);
function query(bytes data, function(bytes memory) external callback) public {
function query(bytes memory data, function(bytes memory) external callback) public {
requests.push(Request(data, callback));
emit NewRequest(requests.length - 1);
}
function reply(uint requestID, bytes response) public {
function reply(uint requestID, bytes memory response) public {
// Here goes the check that the reply comes from a trusted source
requests[requestID].callback(response);
}
Expand All @@ -490,7 +490,7 @@ Another example that uses external function types::
function buySomething() {
oracle.query("USD", this.oracleResponse);
}
function oracleResponse(bytes response) public {
function oracleResponse(bytes memory response) public {
require(
msg.sender == address(oracle),
"Only oracle can call this."
Expand Down Expand Up @@ -544,7 +544,7 @@ memory-stored reference type do not create a copy.
uint[] x; // the data location of x is storage

// the data location of memoryArray is memory
function f(uint[] memoryArray) public {
function f(uint[] memory memoryArray) public {
x = memoryArray; // works, copies the whole array to storage
uint[] storage y = x; // works, assigns a pointer, data location of y is storage
y[7]; // fine, returns the 8th element
Expand All @@ -561,7 +561,7 @@ memory-stored reference type do not create a copy.
}

function g(uint[] storage storageArray) internal {}
function h(uint[] memoryArray) public {}
function h(uint[] memory memoryArray) public {}
}

Summary
Expand Down Expand Up @@ -650,7 +650,7 @@ assigned to a variable right away.
function f() public pure {
g([uint(1), 2, 3]);
}
function g(uint[3] _data) public pure {
function g(uint[3] memory _data) public pure {
// ...
}
}
Expand Down Expand Up @@ -717,7 +717,7 @@ Members
bool[2][] m_pairsOfFlags;
// newPairs is stored in memory - the default for function arguments

function setAllFlagPairs(bool[2][] newPairs) public {
function setAllFlagPairs(bool[2][] memory newPairs) public {
// assignment to a storage array replaces the complete array
m_pairsOfFlags = newPairs;
}
Expand All @@ -743,7 +743,7 @@ Members

bytes m_byteData;

function byteArrays(bytes data) public {
function byteArrays(bytes memory data) public {
// byte arrays ("bytes") are different as they are stored without padding,
// but can be treated identical to "uint8[]"
m_byteData = data;
Expand All @@ -752,11 +752,11 @@ Members
delete m_byteData[2];
}

function addFlag(bool[2] flag) public returns (uint) {
function addFlag(bool[2] memory flag) public returns (uint) {
return m_pairsOfFlags.push(flag);
}

function createMemoryArray(uint size) public pure returns (bytes) {
function createMemoryArray(uint size) public pure returns (bytes memory) {
// Dynamic memory arrays are created using `new`:
uint[2][] memory arrayOfPairs = new uint[2][](size);
// Create a dynamic byte array:
Expand Down
12 changes: 6 additions & 6 deletions test/compilationTests/MultiSigWallet/MultiSigWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ contract MultiSigWallet {
/// @dev Contract constructor sets initial owners and required number of confirmations.
/// @param _owners List of initial owners.
/// @param _required Number of required confirmations.
constructor(address[] _owners, uint _required)
constructor(address[] memory _owners, uint _required)
public
validRequirement(_owners.length, _required)
{
Expand Down Expand Up @@ -185,7 +185,7 @@ contract MultiSigWallet {
/// @param value Transaction ether value.
/// @param data Transaction data payload.
/// @return Returns transaction ID.
function submitTransaction(address destination, uint value, bytes data)
function submitTransaction(address destination, uint value, bytes memory data)
public
returns (uint transactionId)
{
Expand Down Expand Up @@ -261,7 +261,7 @@ contract MultiSigWallet {
/// @param value Transaction ether value.
/// @param data Transaction data payload.
/// @return Returns transaction ID.
function addTransaction(address destination, uint value, bytes data)
function addTransaction(address destination, uint value, bytes memory data)
internal
notNull(destination)
returns (uint transactionId)
Expand Down Expand Up @@ -313,7 +313,7 @@ contract MultiSigWallet {
function getOwners()
public
view
returns (address[])
returns (address[] memory)
{
return owners;
}
Expand All @@ -324,7 +324,7 @@ contract MultiSigWallet {
function getConfirmations(uint transactionId)
public
view
returns (address[] _confirmations)
returns (address[] memory _confirmations)
{
address[] memory confirmationsTemp = new address[](owners.length);
uint count = 0;
Expand All @@ -348,7 +348,7 @@ contract MultiSigWallet {
function getTransactionIds(uint from, uint to, bool pending, bool executed)
public
view
returns (uint[] _transactionIds)
returns (uint[] memory _transactionIds)
{
uint[] memory transactionIdsTemp = new uint[](transactionCount);
uint count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract MultiSigWalletFactory is Factory {
/// @param _owners List of initial owners.
/// @param _required Number of required confirmations.
/// @return Returns wallet address.
function create(address[] _owners, uint _required)
function create(address[] memory _owners, uint _required)
public
returns (address wallet)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet {
/// @param _owners List of initial owners.
/// @param _required Number of required confirmations.
/// @param _dailyLimit Amount in wei, which can be withdrawn without confirmations on a daily basis.
constructor(address[] _owners, uint _required, uint _dailyLimit)
constructor(address[] memory _owners, uint _required, uint _dailyLimit)
public
MultiSigWallet(_owners, _required)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract MultiSigWalletWithDailyLimitFactory is Factory {
/// @param _required Number of required confirmations.
/// @param _dailyLimit Amount in wei, which can be withdrawn without confirmations on a daily basis.
/// @return Returns wallet address.
function create(address[] _owners, uint _required, uint _dailyLimit)
function create(address[] memory _owners, uint _required, uint _dailyLimit)
public
returns (address wallet)
{
Expand Down
2 changes: 1 addition & 1 deletion test/compilationTests/corion/ico.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract ico is safeMath {
uint256 public totalMint;
uint256 public totalPremiumMint;

constructor(address foundation, address priceSet, uint256 exchangeRate, uint256 startBlockNum, address[] genesisAddr, uint256[] genesisValue) {
constructor(address foundation, address priceSet, uint256 exchangeRate, uint256 startBlockNum, address[] memory genesisAddr, uint256[] memory genesisValue) {
/*
Installation function.

Expand Down
12 changes: 6 additions & 6 deletions test/compilationTests/corion/moduleHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ contract moduleHandler is multiOwner, announcementTypes {
modules_s[] public modules;
address public foundationAddress;
uint256 debugModeUntil = block.number + 1000000;



constructor(address[] newOwners) multiOwner(newOwners) {}
constructor(address[] memory newOwners) multiOwner(newOwners) {}
function load(address foundation, bool forReplace, address Token, address Premium, address Publisher, address Schelling, address Provider) {
/*
Loading modulest to ModuleHandler.
Expand All @@ -60,7 +60,7 @@ contract moduleHandler is multiOwner, announcementTypes {
addModule( modules_s(Schelling, keccak256('Schelling'), false, true), ! forReplace);
addModule( modules_s(Provider, keccak256('Provider'), true, true), ! forReplace);
}
function addModule(modules_s input, bool call) internal {
function addModule(modules_s memory input, bool call) internal {
/*
Inside function for registration of the modules in the database.
If the call is false, wont happen any direct call.
Expand All @@ -81,7 +81,7 @@ contract moduleHandler is multiOwner, announcementTypes {
}
modules[id] = input;
}
function getModuleAddressByName(string name) public view returns( bool success, bool found, address addr ) {
function getModuleAddressByName(string memory name) public view returns( bool success, bool found, address addr ) {
/*
Search by name for module. The result is an Ethereum address.

Expand Down Expand Up @@ -109,7 +109,7 @@ contract moduleHandler is multiOwner, announcementTypes {
}
return (true, false, 0);
}
function getModuleIDByName(string name) public view returns( bool success, bool found, uint256 id ) {
function getModuleIDByName(string memory name) public view returns( bool success, bool found, uint256 id ) {
/*
Search by name for module. The result is an index array.

Expand Down Expand Up @@ -177,7 +177,7 @@ contract moduleHandler is multiOwner, announcementTypes {
require( abstractModule(modules[_id].addr).replaceModule(newModule) );
return true;
}

function newModule(string name, address addr, bool schellingEvent, bool transferEvent) external returns (bool success) {
/*
Adding new module to the database. Can be called only by the Publisher contract.
Expand Down
4 changes: 2 additions & 2 deletions test/compilationTests/corion/multiOwner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract multiOwner is safeMath {
/*
Constructor
*/
constructor(address[] newOwners) {
constructor(address[] memory newOwners) {
for ( uint256 a=0 ; a<newOwners.length ; a++ ) {
_addOwner(newOwners[a]);
}
Expand Down Expand Up @@ -41,7 +41,7 @@ contract multiOwner is safeMath {
function ownersForChange() public view returns (uint256 owners) {
return ownerCount * 75 / 100;
}
function calcDoHash(string job, bytes32 data) public pure returns (bytes32 hash) {
function calcDoHash(string memory job, bytes32 data) public pure returns (bytes32 hash) {
return keccak256(abi.encodePacked(job, data));
}
function validDoHash(bytes32 doHash) public view returns (bool valid) {
Expand Down
4 changes: 2 additions & 2 deletions test/compilationTests/corion/premium.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract premium is module, safeMath {

mapping(address => bool) public genesis;

constructor(bool forReplace, address moduleHandler, address dbAddress, address icoContractAddr, address[] genesisAddr, uint256[] genesisValue) {
constructor(bool forReplace, address moduleHandler, address dbAddress, address icoContractAddr, address[] memory genesisAddr, uint256[] memory genesisValue) {
/*
Setup function.
If an ICOaddress is defined then the balance of the genesis addresses will be set as well.
Expand Down Expand Up @@ -246,7 +246,7 @@ contract premium is module, safeMath {
return true;
}

function transferToContract(address from, address to, uint256 amount, bytes extraData) internal {
function transferToContract(address from, address to, uint256 amount, bytes memory extraData) internal {
/*
Inner function in order to transact a contract.

Expand Down
Loading