aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-07-13 07:28:29 +0800
committerGitHub <noreply@github.com>2018-07-13 07:28:29 +0800
commit31e56f9f9976cee44f000226318dca566f0f0b79 (patch)
tree1130854f705de884c446ae7b860a424c77b889b0
parentbab4a3975fd9f49850d11337dc6abf00a2542f1d (diff)
parent3ebfcae8292da1d9f41ff20da1866c424404ee58 (diff)
downloaddexon-solidity-31e56f9f9976cee44f000226318dca566f0f0b79.tar.gz
dexon-solidity-31e56f9f9976cee44f000226318dca566f0f0b79.tar.zst
dexon-solidity-31e56f9f9976cee44f000226318dca566f0f0b79.zip
Merge pull request #4438 from ethereum/address_members_external_tests_docs
Address members used by contracts: update external tests and docs
-rw-r--r--docs/contracts.rst17
-rw-r--r--docs/control-structures.rst8
-rw-r--r--docs/units-and-global-variables.rst4
-rw-r--r--test/compilationTests/corion/ico.sol2
-rw-r--r--test/compilationTests/corion/module.sol4
-rw-r--r--test/compilationTests/corion/token.sol2
-rw-r--r--test/compilationTests/zeppelin/Bounty.sol2
-rw-r--r--test/compilationTests/zeppelin/LimitBalance.sol2
-rw-r--r--test/compilationTests/zeppelin/crowdsale/RefundVault.sol2
-rw-r--r--test/compilationTests/zeppelin/ownership/HasNoEther.sol2
-rw-r--r--test/compilationTests/zeppelin/payment/PullPayment.sol2
11 files changed, 25 insertions, 22 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 862ec54d..fa6df6bf 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -406,7 +406,7 @@ Constant State Variables
State variables can be declared as ``constant``. In this case, they have to be
assigned from an expression which is a constant at compile time. Any expression
-that accesses storage, blockchain data (e.g. ``now``, ``this.balance`` or
+that accesses storage, blockchain data (e.g. ``now``, ``address(this).balance`` or
``block.number``) or
execution data (``msg.value`` or ``gasleft()``) or make calls to external contracts are disallowed. Expressions
that might have a side-effect on memory allocation are allowed, but those that
@@ -505,7 +505,7 @@ Functions can be declared ``pure`` in which case they promise not to read from o
In addition to the list of state modifying statements explained above, the following are considered reading from the state:
#. Reading from state variables.
-#. Accessing ``this.balance`` or ``<address>.balance``.
+#. Accessing ``address(this).balance`` or ``<address>.balance``.
#. Accessing any of the members of ``block``, ``tx``, ``msg`` (with the exception of ``msg.sig`` and ``msg.data``).
#. Calling any function not marked ``pure``.
#. Using inline assembly that contains certain opcodes.
@@ -580,7 +580,7 @@ Like any function, the fallback function can execute complex operations as long
but do not define a fallback function
throw an exception, sending back the Ether (this was different
before Solidity v0.4.0). So if you want your contract to receive Ether,
- you have to implement a fallback function.
+ you have to implement a payable fallback function.
.. warning::
A contract without a payable fallback function can receive Ether as a recipient of a `coinbase transaction` (aka `miner block reward`)
@@ -588,11 +588,11 @@ Like any function, the fallback function can execute complex operations as long
A contract cannot react to such Ether transfers and thus also cannot reject them. This is a design choice of the EVM and Solidity cannot work around it.
- It also means that ``this.balance`` can be higher than the sum of some manual accounting implemented in a contract (i.e. having a counter updated in the fallback function).
+ It also means that ``address(this).balance`` can be higher than the sum of some manual accounting implemented in a contract (i.e. having a counter updated in the fallback function).
::
- pragma solidity ^0.4.0;
+ pragma solidity >0.4.24;
contract Test {
// This function is called for all messages sent to
@@ -613,14 +613,13 @@ Like any function, the fallback function can execute complex operations as long
contract Caller {
function callTest(Test test) public {
- test.call(abi.encodeWithSignature("nonExistingFunction()"));
+ address(test).call(abi.encodeWithSignature("nonExistingFunction()"));
// results in test.x becoming == 1.
- // The following will not compile, but even
- // if someone sends ether to that contract,
+ // If someone sends ether to that contract,
// the transaction will fail and reject the
// Ether.
- //test.send(2 ether);
+ address(test).send(2 ether);
}
}
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index 837a0a90..ead236c4 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -418,18 +418,18 @@ a message string for ``require``, but not for ``assert``.
::
- pragma solidity ^0.4.22;
+ pragma solidity >0.4.24;
contract Sharer {
function sendHalf(address addr) public payable returns (uint balance) {
require(msg.value % 2 == 0, "Even value required.");
- uint balanceBeforeTransfer = this.balance;
+ uint balanceBeforeTransfer = address(this).balance;
addr.transfer(msg.value / 2);
// Since transfer throws an exception on failure and
// cannot call back here, there should be no way for us to
// still have half of the money.
- assert(this.balance == balanceBeforeTransfer - msg.value / 2);
- return this.balance;
+ assert(address(this).balance == balanceBeforeTransfer - msg.value / 2);
+ return address(this).balance;
}
}
diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst
index 61ae51a8..b24b8b71 100644
--- a/docs/units-and-global-variables.rst
+++ b/docs/units-and-global-variables.rst
@@ -181,6 +181,10 @@ For more information, see the section on :ref:`address`.
Use a pattern where the recipient withdraws the money.
.. note::
+ Prior to version 0.5.0, Solidity allowed address members to be accessed by a contract instance, for example ``this.balance``.
+ This is now forbidden and an explicit conversion to address must be done: ``address(this).balance``.
+
+.. note::
If storage variables are accessed via a low-level delegatecall, the storage layout of the two contracts
must align in order for the called contract to correctly access the storage variables of the calling contract by name.
This is of course not the case if storage pointers are passed as function arguments as in the case for
diff --git a/test/compilationTests/corion/ico.sol b/test/compilationTests/corion/ico.sol
index 7b27c201..abb6020b 100644
--- a/test/compilationTests/corion/ico.sol
+++ b/test/compilationTests/corion/ico.sol
@@ -231,7 +231,7 @@ contract ico is safeMath {
require( ! aborted );
require( token(tokenAddr).mint(foundationAddress, token(tokenAddr).totalSupply() * 96 / 100) );
require( premium(premiumAddr).mint(foundationAddress, totalMint / 5000 - totalPremiumMint) );
- require( foundationAddress.send(this.balance) );
+ require( foundationAddress.send(address(this).balance) );
require( token(tokenAddr).closeIco() );
require( premium(premiumAddr).closeIco() );
}
diff --git a/test/compilationTests/corion/module.sol b/test/compilationTests/corion/module.sol
index 62f44af7..e0084ea5 100644
--- a/test/compilationTests/corion/module.sol
+++ b/test/compilationTests/corion/module.sol
@@ -95,8 +95,8 @@ contract module {
if ( _balance > 0 ) {
require( abstractModuleHandler(moduleHandlerAddress).transfer(address(this), newModuleAddress, _balance, false) );
}
- if ( this.balance > 0 ) {
- require( newModuleAddress.send(this.balance) );
+ if ( address(this).balance > 0 ) {
+ require( newModuleAddress.send(address(this).balance) );
}
moduleStatus = status.Disconnected;
}
diff --git a/test/compilationTests/corion/token.sol b/test/compilationTests/corion/token.sol
index 195b4ada..8ca18083 100644
--- a/test/compilationTests/corion/token.sol
+++ b/test/compilationTests/corion/token.sol
@@ -73,7 +73,7 @@ contract token is safeMath, module, announcementTypes {
if ( ! forReplace ) {
require( db.replaceOwner(this) );
assert( genesisAddr.length == genesisValue.length );
- require( this.balance >= genesisAddr.length * 0.2 ether );
+ require( address(this).balance >= genesisAddr.length * 0.2 ether );
for ( uint256 a=0 ; a<genesisAddr.length ; a++ ) {
genesis[genesisAddr[a]] = true;
require( db.increase(genesisAddr[a], genesisValue[a]) );
diff --git a/test/compilationTests/zeppelin/Bounty.sol b/test/compilationTests/zeppelin/Bounty.sol
index 5b2124ca..a5e75cd3 100644
--- a/test/compilationTests/zeppelin/Bounty.sol
+++ b/test/compilationTests/zeppelin/Bounty.sol
@@ -55,7 +55,7 @@ contract Bounty is PullPayment, Destructible {
if (target.checkInvariant()) {
throw;
}
- asyncSend(researcher, this.balance);
+ asyncSend(researcher, address(this).balance);
claimed = true;
}
diff --git a/test/compilationTests/zeppelin/LimitBalance.sol b/test/compilationTests/zeppelin/LimitBalance.sol
index cf040097..9682ff1c 100644
--- a/test/compilationTests/zeppelin/LimitBalance.sol
+++ b/test/compilationTests/zeppelin/LimitBalance.sol
@@ -23,7 +23,7 @@ contract LimitBalance {
* @dev Checks if limit was reached. Case true, it throws.
*/
modifier limitedPayable() {
- if (this.balance > limit) {
+ if (address(this).balance > limit) {
throw;
}
_;
diff --git a/test/compilationTests/zeppelin/crowdsale/RefundVault.sol b/test/compilationTests/zeppelin/crowdsale/RefundVault.sol
index 19346c42..b7db8ef2 100644
--- a/test/compilationTests/zeppelin/crowdsale/RefundVault.sol
+++ b/test/compilationTests/zeppelin/crowdsale/RefundVault.sol
@@ -37,7 +37,7 @@ contract RefundVault is Ownable {
require(state == State.Active);
state = State.Closed;
emit Closed();
- wallet.transfer(this.balance);
+ wallet.transfer(address(this).balance);
}
function enableRefunds() public onlyOwner {
diff --git a/test/compilationTests/zeppelin/ownership/HasNoEther.sol b/test/compilationTests/zeppelin/ownership/HasNoEther.sol
index ffd1d76f..9f294679 100644
--- a/test/compilationTests/zeppelin/ownership/HasNoEther.sol
+++ b/test/compilationTests/zeppelin/ownership/HasNoEther.sol
@@ -37,7 +37,7 @@ contract HasNoEther is Ownable {
* @dev Transfer all Ether held by the contract to the owner.
*/
function reclaimEther() external onlyOwner {
- if(!owner.send(this.balance)) {
+ if(!owner.send(address(this).balance)) {
throw;
}
}
diff --git a/test/compilationTests/zeppelin/payment/PullPayment.sol b/test/compilationTests/zeppelin/payment/PullPayment.sol
index 6db7df78..2f3e1b51 100644
--- a/test/compilationTests/zeppelin/payment/PullPayment.sol
+++ b/test/compilationTests/zeppelin/payment/PullPayment.sol
@@ -36,7 +36,7 @@ contract PullPayment {
throw;
}
- if (this.balance < payment) {
+ if (address(this).balance < payment) {
throw;
}