mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Split fallback function and introduce "fallback()" and "receive()" syntax.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
contract TransferTest {
|
||||
function() external payable {
|
||||
fallback() external payable {
|
||||
// This used to cause an ICE
|
||||
address(this).transfer;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
contract C {
|
||||
uint x;
|
||||
uint y;
|
||||
fallback () payable external { ++x; }
|
||||
receive () payable external { ++y; }
|
||||
function f() external returns (uint, uint) { return (x, y); }
|
||||
}
|
||||
// ----
|
||||
// f() -> 0, 0
|
||||
// () ->
|
||||
// f() -> 0, 1
|
||||
// (), 1 ether ->
|
||||
// f() -> 0, 2
|
||||
// (): 1 ->
|
||||
// f() -> 1, 2
|
||||
// (), 1 ether: 1 ->
|
||||
// f() -> 2, 2
|
||||
@@ -0,0 +1,10 @@
|
||||
contract A {
|
||||
uint data;
|
||||
fallback() external { data = 1; }
|
||||
function getData() public returns (uint r) { return data; }
|
||||
}
|
||||
contract B is A {}
|
||||
// ----
|
||||
// getData() -> 0
|
||||
// (): 42 ->
|
||||
// getData() -> 1
|
||||
@@ -0,0 +1,17 @@
|
||||
contract A {
|
||||
uint public x;
|
||||
// Signature is d88e0b00
|
||||
function fow() public { x = 3; }
|
||||
fallback () external { x = 2; }
|
||||
}
|
||||
// ----
|
||||
// (): hex"d88e0b"
|
||||
// x() -> 2
|
||||
// (): hex"d88e0b00"
|
||||
// x() -> 3
|
||||
// (): hex"d88e"
|
||||
// x() -> 2
|
||||
// (): hex"d88e0b00"
|
||||
// x() -> 3
|
||||
// (): hex"d8"
|
||||
// x() -> 2
|
||||
@@ -0,0 +1,12 @@
|
||||
contract A {
|
||||
uint public x;
|
||||
receive () external payable { ++x; }
|
||||
}
|
||||
// ----
|
||||
// x() -> 0
|
||||
// ()
|
||||
// x() -> 1
|
||||
// (), 1 ether
|
||||
// x() -> 2
|
||||
// (): hex"00" -> FAILURE
|
||||
// (), 1 ether: hex"00" -> FAILURE
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
receive () payable external { }
|
||||
}
|
||||
// ----
|
||||
// (), 1 ether
|
||||
// (), 1 ether: 1 -> FAILURE
|
||||
@@ -0,0 +1,12 @@
|
||||
contract A {
|
||||
uint data;
|
||||
receive() external payable { ++data; }
|
||||
function getData() public returns (uint r) { return data; }
|
||||
}
|
||||
contract B is A {}
|
||||
// ----
|
||||
// getData() -> 0
|
||||
// () ->
|
||||
// getData() -> 1
|
||||
// (), 1 ether ->
|
||||
// getData() -> 2
|
||||
@@ -2,7 +2,7 @@ contract A {
|
||||
uint public data;
|
||||
uint public balance;
|
||||
bytes public externalData;
|
||||
function() external payable {
|
||||
fallback() external payable {
|
||||
data += 1;
|
||||
balance = msg.value;
|
||||
externalData = msg.data;
|
||||
|
||||
Reference in New Issue
Block a user