aboutsummaryrefslogtreecommitdiffstats
path: root/docs/contracts.rst
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-08-06 20:48:59 +0800
committerchriseth <c@ethdev.com>2016-08-17 17:29:31 +0800
commit9c83109549547c8fe308969f924d3c07ce2cac76 (patch)
tree3cf99945327a653af0845201364aed7bbab57874 /docs/contracts.rst
parente7683f4722791d39ca63913ec98feb1ea9f5164d (diff)
downloaddexon-solidity-9c83109549547c8fe308969f924d3c07ce2cac76.tar.gz
dexon-solidity-9c83109549547c8fe308969f924d3c07ce2cac76.tar.zst
dexon-solidity-9c83109549547c8fe308969f924d3c07ce2cac76.zip
BREAKING: return only exits current function/modifier
Diffstat (limited to 'docs/contracts.rst')
-rw-r--r--docs/contracts.rst40
1 files changed, 33 insertions, 7 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 3d592ecf..5f370951 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -314,14 +314,40 @@ inheritable properties of contracts and may be overridden by derived contracts.
}
}
+ contract Mutex {
+ bool locked;
+ modifier noReentrancy() {
+ if (locked) throw;
+ locked = true;
+ _
+ locked = false;
+ }
+
+ /// This function is protected by a mutex, which means that
+ /// reentrant calls from within msg.sender.call cannot call f again.
+ /// The `return 7` statement assigns 7 to the return value but still
+ /// executes the statement `locked = false` in the modifier.
+ function f() noReentrancy returns (uint) {
+ if (!msg.sender.call()) throw;
+ return 7;
+ }
+ }
+
Multiple modifiers can be applied to a function by specifying them in a
-whitespace-separated list and will be evaluated in order. Explicit returns from
-a modifier or function body immediately leave the whole function, while control
-flow reaching the end of a function or modifier body continues after the "_" in
-the preceding modifier. Arbitrary expressions are allowed for modifier
-arguments and in this context, all symbols visible from the function are
-visible in the modifier. Symbols introduced in the modifier are not visible in
-the function (as they might change by overriding).
+whitespace-separated list and will be evaluated in order.
+
+.. warning::
+ In an earlier version of Solidity, ``return`` statements in functions
+ having modifiers behaved differently.
+
+Explicit returns from a modifier or function body only leave the current
+modifier or function body. Return variables are assigned and
+control flow continues after the "_" in the preceding modifier.
+
+Arbitrary expressions are allowed for modifier arguments and in this context,
+all symbols visible from the function are visible in the modifier. Symbols
+introduced in the modifier are not visible in the function (as they might
+change by overriding).
.. index:: ! constant