Skip to content

Commit eeef82b

Browse files
committed
Fallback function has to be external: backwards-compatible changes.
1 parent 4268062 commit eeef82b

43 files changed

Lines changed: 123 additions & 105 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/contracts.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ Fallback Function
543543
=================
544544

545545
A contract can have exactly one unnamed function. This function cannot have
546-
arguments and cannot return anything.
546+
arguments, cannot return anything and has to have ``external`` visibility.
547547
It is executed on a call to the contract if none of the other
548548
functions match the given function identifier (or if no data was supplied at
549549
all).
@@ -591,15 +591,15 @@ Like any function, the fallback function can execute complex operations as long
591591
// Sending Ether to this contract will cause an exception,
592592
// because the fallback function does not have the `payable`
593593
// modifier.
594-
function() public { x = 1; }
594+
function() external { x = 1; }
595595
uint x;
596596
}
597597

598598

599599
// This contract keeps all Ether sent to it with no way
600600
// to get it back.
601601
contract Sink {
602-
function() public payable { }
602+
function() external payable { }
603603
}
604604

605605
contract Caller {

docs/security-considerations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Now someone tricks you into sending ether to the address of this attack wallet:
213213
owner = msg.sender;
214214
}
215215

216-
function() public {
216+
function() external {
217217
TxUserWallet(msg.sender).transferTo(owner, msg.sender.balance);
218218
}
219219
}

docs/style-guide.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Yes::
278278
...
279279
}
280280

281-
function() public {
281+
function() external {
282282
...
283283
}
284284

@@ -308,6 +308,10 @@ No::
308308
// External functions
309309
// ...
310310

311+
function() external {
312+
...
313+
}
314+
311315
// Private functions
312316
// ...
313317

@@ -318,10 +322,6 @@ No::
318322
...
319323
}
320324

321-
function() public {
322-
...
323-
}
324-
325325
// Internal functions
326326
// ...
327327
}
@@ -374,13 +374,13 @@ Don't include a whitespace in the fallback function:
374374

375375
Yes::
376376

377-
function() public {
377+
function() external {
378378
...
379379
}
380380

381381
No::
382382

383-
function () public {
383+
function () external {
384384
...
385385
}
386386

test/compilationTests/MultiSigWallet/MultiSigWallet.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ contract MultiSigWallet {
9090

9191
/// @dev Fallback function allows to deposit ether.
9292
function()
93+
external
9394
payable
9495
{
9596
if (msg.value > 0)

test/compilationTests/corion/ico.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ contract ico is safeMath {
275275
require( msg.sender.send(_val) );
276276
}
277277

278-
function () payable {
278+
function () external payable {
279279
/*
280280
Callback function. Simply calls the buy function as a beneficiary and there is no affilate address.
281281
If they call the contract without any function then this process will be taken place.

test/compilationTests/zeppelin/Bounty.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ contract Bounty is PullPayment, Destructible {
1818
/**
1919
* @dev Fallback function allowing the contract to recieve funds, if they haven't already been claimed.
2020
*/
21-
function() payable {
21+
function() external payable {
2222
if (claimed) {
2323
throw;
2424
}

test/compilationTests/zeppelin/MultisigWallet.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit {
3939
/**
4040
* @dev Fallback function, receives value and emits a deposit event.
4141
*/
42-
function() payable {
42+
function() external payable {
4343
// just being sent some cash?
4444
if (msg.value > 0)
4545
emit Deposit(msg.sender, msg.value);

test/compilationTests/zeppelin/crowdsale/Crowdsale.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ contract Crowdsale {
6161

6262

6363
// fallback function can be used to buy tokens
64-
function () payable {
64+
function () external payable {
6565
buyTokens(msg.sender);
6666
}
6767

test/contracts/Wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ contract Wallet is multisig, multiowned, daylimit {
379379
}
380380
381381
// gets called when no other function matches
382-
function() payable {
382+
function() external payable {
383383
// just being sent some cash?
384384
if (msg.value > 0)
385385
emit Deposit(msg.sender, msg.value);

test/libsolidity/GasMeter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback)
301301
char const* sourceCode = R"(
302302
contract A {
303303
uint public x;
304-
function() { x = 2; }
304+
function() external { x = 2; }
305305
}
306306
)";
307307
testCreationTimeGas(sourceCode);

0 commit comments

Comments
 (0)