Split fallback function and introduce "fallback()" and "receive()" syntax.

This commit is contained in:
Daniel Kirchner
2019-11-04 17:17:58 +01:00
parent 3d625cc239
commit 3321fc56ea
137 changed files with 1340 additions and 386 deletions
@@ -1,5 +1,5 @@
contract test {
function() external {}
fallback() external {}
}
// ----
// :test
@@ -1,5 +1,5 @@
contract test {
function () external payable {}
fallback () external payable {}
}
// ----
// :test
@@ -0,0 +1,16 @@
contract test {
receive() external payable {}
fallback() external {}
}
// ----
// :test
// [
// {
// "stateMutability": "nonpayable",
// "type": "fallback"
// },
// {
// "stateMutability": "payable",
// "type": "receive"
// }
// ]
@@ -0,0 +1,11 @@
contract test {
receive() external payable {}
}
// ----
// :test
// [
// {
// "stateMutability": "payable",
// "type": "receive"
// }
// ]
+1 -1
View File
@@ -1,5 +1,5 @@
contract C {
function() external payable {
fallback() external payable {
}
}
@@ -0,0 +1,108 @@
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
9
]
},
"id": 10,
"nodeType": "SourceUnit",
"nodes":
[
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 9,
"linearizedBaseContracts":
[
9
],
"name": "C",
"nodeType": "ContractDefinition",
"nodes":
[
{
"body":
{
"id": 3,
"nodeType": "Block",
"src": "42:5:1",
"statements": []
},
"documentation": null,
"id": 4,
"implemented": true,
"kind": "receive",
"modifiers": [],
"name": "",
"nodeType": "FunctionDefinition",
"overrides": null,
"parameters":
{
"id": 1,
"nodeType": "ParameterList",
"parameters": [],
"src": "22:2:1"
},
"returnParameters":
{
"id": 2,
"nodeType": "ParameterList",
"parameters": [],
"src": "42:0:1"
},
"scope": 9,
"src": "15:32:1",
"stateMutability": "payable",
"superFunction": null,
"visibility": "external"
},
{
"body":
{
"id": 7,
"nodeType": "Block",
"src": "78:5:1",
"statements": []
},
"documentation": null,
"id": 8,
"implemented": true,
"kind": "fallback",
"modifiers": [],
"name": "",
"nodeType": "FunctionDefinition",
"overrides": null,
"parameters":
{
"id": 5,
"nodeType": "ParameterList",
"parameters": [],
"src": "58:2:1"
},
"returnParameters":
{
"id": 6,
"nodeType": "ParameterList",
"parameters": [],
"src": "78:0:1"
},
"scope": 9,
"src": "50:33:1",
"stateMutability": "payable",
"superFunction": null,
"visibility": "external"
}
],
"scope": 10,
"src": "0:85:1"
}
],
"src": "0:86:1"
}
@@ -0,0 +1,8 @@
contract C {
receive() external payable {
}
fallback() external payable {
}
}
// ----
@@ -0,0 +1,176 @@
{
"attributes":
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
9
]
}
},
"children":
[
{
"attributes":
{
"abstract": false,
"baseContracts":
[
null
],
"contractDependencies":
[
null
],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"linearizedBaseContracts":
[
9
],
"name": "C",
"scope": 10
},
"children":
[
{
"attributes":
{
"documentation": null,
"implemented": true,
"isConstructor": false,
"kind": "receive",
"modifiers":
[
null
],
"name": "",
"overrides": null,
"scope": 9,
"stateMutability": "payable",
"superFunction": null,
"visibility": "external"
},
"children":
[
{
"attributes":
{
"parameters":
[
null
]
},
"children": [],
"id": 1,
"name": "ParameterList",
"src": "22:2:1"
},
{
"attributes":
{
"parameters":
[
null
]
},
"children": [],
"id": 2,
"name": "ParameterList",
"src": "42:0:1"
},
{
"attributes":
{
"statements":
[
null
]
},
"children": [],
"id": 3,
"name": "Block",
"src": "42:5:1"
}
],
"id": 4,
"name": "FunctionDefinition",
"src": "15:32:1"
},
{
"attributes":
{
"documentation": null,
"implemented": true,
"isConstructor": false,
"kind": "fallback",
"modifiers":
[
null
],
"name": "",
"overrides": null,
"scope": 9,
"stateMutability": "payable",
"superFunction": null,
"visibility": "external"
},
"children":
[
{
"attributes":
{
"parameters":
[
null
]
},
"children": [],
"id": 5,
"name": "ParameterList",
"src": "58:2:1"
},
{
"attributes":
{
"parameters":
[
null
]
},
"children": [],
"id": 6,
"name": "ParameterList",
"src": "78:0:1"
},
{
"attributes":
{
"statements":
[
null
]
},
"children": [],
"id": 7,
"name": "Block",
"src": "78:5:1"
}
],
"id": 8,
"name": "FunctionDefinition",
"src": "50:33:1"
}
],
"id": 9,
"name": "ContractDefinition",
"src": "0:85:1"
}
],
"id": 10,
"name": "SourceUnit",
"src": "0:86:1"
}
@@ -1,5 +1,5 @@
contract C {
function() external {}
fallback() external {}
}
// ----
@@ -0,0 +1,72 @@
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
5
]
},
"id": 6,
"nodeType": "SourceUnit",
"nodes":
[
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 5,
"linearizedBaseContracts":
[
5
],
"name": "C",
"nodeType": "ContractDefinition",
"nodes":
[
{
"body":
{
"id": 3,
"nodeType": "Block",
"src": "42:5:1",
"statements": []
},
"documentation": null,
"id": 4,
"implemented": true,
"kind": "receive",
"modifiers": [],
"name": "",
"nodeType": "FunctionDefinition",
"overrides": null,
"parameters":
{
"id": 1,
"nodeType": "ParameterList",
"parameters": [],
"src": "22:2:1"
},
"returnParameters":
{
"id": 2,
"nodeType": "ParameterList",
"parameters": [],
"src": "42:0:1"
},
"scope": 5,
"src": "15:32:1",
"stateMutability": "payable",
"superFunction": null,
"visibility": "external"
}
],
"scope": 6,
"src": "0:49:1"
}
],
"src": "0:50:1"
}
@@ -0,0 +1,6 @@
contract C {
receive() external payable {
}
}
// ----
@@ -0,0 +1,112 @@
{
"attributes":
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
5
]
}
},
"children":
[
{
"attributes":
{
"abstract": false,
"baseContracts":
[
null
],
"contractDependencies":
[
null
],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"linearizedBaseContracts":
[
5
],
"name": "C",
"scope": 6
},
"children":
[
{
"attributes":
{
"documentation": null,
"implemented": true,
"isConstructor": false,
"kind": "receive",
"modifiers":
[
null
],
"name": "",
"overrides": null,
"scope": 5,
"stateMutability": "payable",
"superFunction": null,
"visibility": "external"
},
"children":
[
{
"attributes":
{
"parameters":
[
null
]
},
"children": [],
"id": 1,
"name": "ParameterList",
"src": "22:2:1"
},
{
"attributes":
{
"parameters":
[
null
]
},
"children": [],
"id": 2,
"name": "ParameterList",
"src": "42:0:1"
},
{
"attributes":
{
"statements":
[
null
]
},
"children": [],
"id": 3,
"name": "Block",
"src": "42:5:1"
}
],
"id": 4,
"name": "FunctionDefinition",
"src": "15:32:1"
}
],
"id": 5,
"name": "ContractDefinition",
"src": "0:49:1"
}
],
"id": 6,
"name": "SourceUnit",
"src": "0:50:1"
}
+1 -1
View File
@@ -313,7 +313,7 @@ BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback)
char const* sourceCode = R"(
contract A {
uint public x;
function() external { x = 2; }
fallback() external { x = 2; }
}
)";
testCreationTimeGas(sourceCode);
+27 -66
View File
@@ -1236,7 +1236,7 @@ BOOST_AUTO_TEST_CASE(transfer_ether)
}
contract C {
function () external payable {
receive () external payable {
revert();
}
}
@@ -1900,7 +1900,7 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses)
{
char const* sourceCode = R"(
contract helper {
function() external payable { } // can receive ether
receive() external payable { } // can receive ether
}
contract test {
helper h;
@@ -2514,24 +2514,6 @@ BOOST_AUTO_TEST_CASE(super_alone)
)
}
BOOST_AUTO_TEST_CASE(inherited_fallback_function)
{
char const* sourceCode = R"(
contract A {
uint data;
function() external { data = 1; }
function getData() public returns (uint r) { return data; }
}
contract B is A {}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode, 0, "B");
ABI_CHECK(callContractFunction("getData()"), encodeArgs(0));
ABI_CHECK(callContractFunction(""), encodeArgs());
ABI_CHECK(callContractFunction("getData()"), encodeArgs(1));
)
}
BOOST_AUTO_TEST_CASE(default_fallback_throws)
{
char const* sourceCode = R"YY(
@@ -2561,27 +2543,6 @@ BOOST_AUTO_TEST_CASE(default_fallback_throws)
}
}
BOOST_AUTO_TEST_CASE(short_data_calls_fallback)
{
char const* sourceCode = R"(
contract A {
uint public x;
// Signature is d88e0b00
function fow() public { x = 3; }
function () external { x = 2; }
}
)";
compileAndRun(sourceCode);
// should call fallback
sendMessage(asBytes("\xd8\x8e\x0b"), false, 0);
BOOST_CHECK(m_transactionSuccessful);
ABI_CHECK(callContractFunction("x()"), encodeArgs(2));
// should call function
sendMessage(asBytes(string("\xd8\x8e\x0b") + string(1, 0)), false, 0);
BOOST_CHECK(m_transactionSuccessful);
ABI_CHECK(callContractFunction("x()"), encodeArgs(3));
}
BOOST_AUTO_TEST_CASE(event)
{
char const* sourceCode = R"(
@@ -3363,13 +3324,13 @@ BOOST_AUTO_TEST_CASE(generic_call)
char const* sourceCode = R"**(
contract receiver {
uint public received;
function receive(uint256 x) public payable { received = x; }
function recv(uint256 x) public payable { received = x; }
}
contract sender {
constructor() public payable {}
function doSend(address rec) public returns (uint d)
{
bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)")));
bytes4 signature = bytes4(bytes32(keccak256("recv(uint256)")));
rec.call.value(2)(abi.encodeWithSelector(signature, 23));
return receiver(rec).received();
}
@@ -3390,7 +3351,7 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall)
address public sender;
uint public value;
constructor() public payable {}
function receive(uint256 x) public payable { received = x; sender = msg.sender; value = msg.value; }
function recv(uint256 x) public payable { received = x; sender = msg.sender; value = msg.value; }
}
contract Sender {
uint public received;
@@ -3399,7 +3360,7 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall)
constructor() public payable {}
function doSend(address rec) public payable
{
bytes4 signature = bytes4(bytes32(keccak256("receive(uint256)")));
bytes4 signature = bytes4(bytes32(keccak256("recv(uint256)")));
(bool success,) = rec.delegatecall(abi.encodeWithSelector(signature, 23));
success;
}
@@ -3588,12 +3549,12 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes)
char const* sourceCode = R"(
contract receiver {
uint public received;
function receive(uint x) public { received += x + 1; }
function() external { received = 0x80; }
function recv(uint x) public { received += x + 1; }
fallback() external { received = 0x80; }
}
contract sender {
constructor() public { rec = new receiver(); }
function() external { savedData = msg.data; }
fallback() external { savedData = msg.data; }
function forward() public returns (bool) { address(rec).call(savedData); return true; }
function clear() public returns (bool) { delete savedData; return true; }
function val() public returns (uint) { return rec.received(); }
@@ -3602,7 +3563,7 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes)
}
)";
compileAndRun(sourceCode, 0, "sender");
ABI_CHECK(callContractFunction("receive(uint256)", 7), bytes());
ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes());
ABI_CHECK(callContractFunction("val()"), encodeArgs(0));
ABI_CHECK(callContractFunction("forward()"), encodeArgs(true));
ABI_CHECK(callContractFunction("val()"), encodeArgs(8));
@@ -3617,7 +3578,7 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length)
char const* sourceCode = R"(
contract receiver {
uint public calledLength;
function() external { calledLength = msg.data.length; }
fallback() external { calledLength = msg.data.length; }
}
contract sender {
receiver rec;
@@ -3661,12 +3622,12 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign)
char const* sourceCode = R"(
contract receiver {
uint public received;
function receive(uint x) public { received += x + 1; }
function() external { received = 0x80; }
function recv(uint x) public { received += x + 1; }
fallback() external { received = 0x80; }
}
contract sender {
constructor() public { rec = new receiver(); }
function() external { savedData1 = savedData2 = msg.data; }
fallback() external { savedData1 = savedData2 = msg.data; }
function forward(bool selector) public returns (bool) {
if (selector) { address(rec).call(savedData1); delete savedData1; }
else { address(rec).call(savedData2); delete savedData2; }
@@ -3679,7 +3640,7 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign)
}
)";
compileAndRun(sourceCode, 0, "sender");
ABI_CHECK(callContractFunction("receive(uint256)", 7), bytes());
ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes());
ABI_CHECK(callContractFunction("val()"), encodeArgs(0));
ABI_CHECK(callContractFunction("forward(bool)", true), encodeArgs(true));
ABI_CHECK(callContractFunction("val()"), encodeArgs(8));
@@ -3693,7 +3654,7 @@ BOOST_AUTO_TEST_CASE(delete_removes_bytes_data)
{
char const* sourceCode = R"(
contract c {
function() external { data = msg.data; }
fallback() external { data = msg.data; }
function del() public returns (bool) { delete data; return true; }
bytes data;
}
@@ -3710,7 +3671,7 @@ BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data)
char const* sourceCode = R"(
contract c {
function set() public returns (bool) { data = msg.data; return true; }
function() external { data = msg.data; }
fallback() external { data = msg.data; }
bytes data;
}
)";
@@ -6205,7 +6166,7 @@ BOOST_AUTO_TEST_CASE(failing_send)
char const* sourceCode = R"(
contract Helper {
uint[] data;
function () external {
fallback () external {
data[9]; // trigger exception
}
}
@@ -6225,11 +6186,11 @@ BOOST_AUTO_TEST_CASE(failing_send)
BOOST_AUTO_TEST_CASE(send_zero_ether)
{
// Sending zero ether to a contract should still invoke the fallback function
// Sending zero ether to a contract should still invoke the receive ether function
// (it previously did not because the gas stipend was not provided by the EVM)
char const* sourceCode = R"(
contract Receiver {
function () external payable {
receive () external payable {
}
}
contract Main {
@@ -8804,7 +8765,7 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library)
function f(address payable x) public returns (bool) {
return x.send(1);
}
function () external payable {}
receive () external payable {}
}
)";
compileAndRun(sourceCode, 0, "lib");
@@ -10461,7 +10422,7 @@ BOOST_AUTO_TEST_CASE(mutex)
else
return fund.withdrawUnprotected(10);
}
function() external payable {
fallback() external payable {
callDepth++;
if (callDepth < 4)
attackInternal();
@@ -10526,7 +10487,7 @@ BOOST_AUTO_TEST_CASE(payable_function)
function f() payable public returns (uint) {
return msg.value;
}
function() external payable {
fallback() external payable {
a = msg.value + 1;
}
}
@@ -10568,7 +10529,7 @@ BOOST_AUTO_TEST_CASE(non_payable_throw)
function msgvalue() internal returns (uint) {
return msg.value;
}
function() external {
fallback() external {
update();
}
function update() internal {
@@ -12312,7 +12273,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_transfer)
{
char const* sourceCode = R"(
contract D {
function() external payable {
receive() external payable {
revert("message");
}
function f() public {
@@ -12469,7 +12430,7 @@ BOOST_AUTO_TEST_CASE(interface_contract)
interface I {
event A();
function f() external returns (bool);
function() external payable;
fallback() external payable;
}
contract A is I {
@@ -12481,7 +12442,7 @@ BOOST_AUTO_TEST_CASE(interface_contract)
return true;
}
function() external payable {
fallback() override external payable {
}
}
+4 -4
View File
@@ -2,15 +2,15 @@ contract Small {
uint public a;
uint[] public b;
function f1(uint x) public returns (uint) { a = x; b[uint8(msg.data[0])] = x; }
function () external payable {}
fallback () external payable {}
}
// ----
// creation:
// codeDepositCost: 83800
// codeDepositCost: 84800
// executionCost: 135
// totalCost: 83935
// totalCost: 84935
// external:
// fallback: 118
// fallback: 129
// a(): 383
// b(uint256): 802
// f1(uint256): 40663
@@ -2,7 +2,7 @@ contract Small {
uint public a;
uint[] public b;
function f1(uint x) public returns (uint) { a = x; b[uint8(msg.data[0])] = x; }
function () external payable {}
fallback () external payable {}
}
// ====
// optimize: true
@@ -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;
@@ -25,7 +25,7 @@ contract B is A {
address public mySistersAddress = 0x999999cf1046e68e36E1aA2E0E07105eDDD1f08E;
function () external {
fallback () external {
used = 0;
}
@@ -0,0 +1,5 @@
contract C {
fallback(uint256) external {}
}
// ----
// TypeError: (25-34): Fallback function cannot take parameters.
@@ -1,6 +1,6 @@
contract C {
// Check that visibility is also enforced for the fallback function.
function() {}
fallback() {}
}
// ----
// SyntaxError: (90-103): No visibility specified. Did you intend to add "external"?
@@ -0,0 +1,5 @@
contract C {
function fallback() external pure {}
}
// ----
// Warning: (26-34): This function is named "fallback" but is not the fallback function of the contract. If you intend this to be a fallback function, use "fallback(...) { ... }" without the "function" keyword to define it.
@@ -0,0 +1,5 @@
contract C {
function() external {}
}
// ----
// ParserError: (37-38): Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the "fallback" keyword or the "ether" keyword instead.
@@ -0,0 +1,6 @@
contract A {
receive() external payable { }
}
contract C is A {
fallback() external payable { }
}
@@ -0,0 +1,3 @@
contract C {
fallback() external payable { }
}
@@ -0,0 +1,6 @@
contract C {
fallback() external payable { }
function f() public pure { }
}
// ----
// Warning: (0-83): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
@@ -0,0 +1,8 @@
contract A {
function f() external pure {}
}
contract C is A {
fallback() external payable { }
}
// ----
// Warning: (49-104): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
@@ -0,0 +1,4 @@
contract C {
fallback() external payable { }
function f() internal pure { }
}
@@ -1,6 +1,6 @@
contract C {
uint x;
function() external pure { x = 2; }
fallback() external pure { x = 2; }
}
// ----
// TypeError: (29-64): Fallback function must be payable or non-payable, but is "pure".
@@ -0,0 +1,5 @@
contract C {
fallback() external returns (bytes memory, bytes memory) {}
}
// ----
// TypeError: (45-73): Fallback function can only have a single "bytes memory" return value.
@@ -0,0 +1,5 @@
contract C {
fallback() external returns (uint256) {}
}
// ----
// TypeError: (45-54): Fallback function can only have a single "bytes memory" return value.
@@ -0,0 +1,5 @@
contract C {
fallback() external returns (bytes memory) {}
}
// ----
// TypeError: (45-59): Return values for fallback functions are not yet implemented.
@@ -1,6 +1,6 @@
contract C {
uint x;
function() external view { x = 2; }
fallback() external view { x = 2; }
}
// ----
// TypeError: (29-64): Fallback function must be payable or non-payable, but is "view".
@@ -1,4 +1,4 @@
==== Source: a ====
contract A {}
==== Source: dir/a/b/c ====
import "../../.././a" as x; contract B is x.A { function() external { x.A r = x.A(20); r; } }
import "../../.././a" as x; contract B is x.A { fallback() external { x.A r = x.A(20); r; } }
@@ -0,0 +1,8 @@
contract C {
receive() external payable {}
}
contract D is C {
fallback() override external {}
}
// ----
// TypeError: (76-84): Function has override specified but does not override anything.
@@ -0,0 +1,6 @@
contract C {
fallback() external {}
}
contract D is C {
fallback() override external {}
}
@@ -0,0 +1,8 @@
contract C {
fallback() external {}
}
contract D is C {
}
contract E is D {
fallback() override external {}
}
@@ -0,0 +1,8 @@
contract C {
fallback() external {}
}
contract D is C {
fallback() external {}
}
// ----
// TypeError: (58-80): Overriding function is missing 'override' specifier.
@@ -0,0 +1,10 @@
contract C {
fallback() external {}
}
contract D is C {
}
contract E is D {
fallback() external {}
}
// ----
// TypeError: (78-100): Overriding function is missing 'override' specifier.
@@ -0,0 +1,8 @@
contract C {
fallback() external {}
}
contract D is C {
receive() override external payable {}
}
// ----
// TypeError: (68-76): Function has override specified but does not override anything.
@@ -0,0 +1,6 @@
contract C {
receive() external payable {}
}
contract D is C {
receive() override external payable {}
}
@@ -0,0 +1,8 @@
contract C {
receive() external payable {}
}
contract D is C {
}
contract E is D {
receive() override external payable {}
}
@@ -0,0 +1,8 @@
contract C {
receive() external payable {}
}
contract D is C {
receive() external payable {}
}
// ----
// TypeError: (65-94): Overriding function is missing 'override' specifier.
@@ -0,0 +1,10 @@
contract C {
receive() external payable {}
}
contract D is C {
}
contract E is D {
receive() external payable {}
}
// ----
// TypeError: (85-114): Overriding function is missing 'override' specifier.
@@ -1,6 +1,6 @@
contract C {
uint[] x;
function() external {
fallback() external {
uint[] storage y = x;
assembly {
pop(y)
@@ -1,6 +1,6 @@
contract C {
uint[] x;
function() external {
fallback() external {
uint[] storage y = x;
assembly {
y_slot := 1
@@ -1,6 +1,6 @@
contract C {
uint[] x;
function() external {
fallback() external {
uint[] storage y = x;
assembly {
pop(y_slot)
@@ -1,6 +1,6 @@
contract C {
uint[] x;
function() external {
fallback() external {
uint[] memory y = x;
assembly {
pop(y_slot)
@@ -1,4 +1,4 @@
contract C {
uint x;
function() external { x = 2; }
fallback() external { x = 2; }
}
@@ -1,6 +1,6 @@
contract C {
uint x;
function(uint a) external { x = 2; }
fallback(uint a) external { x = 2; }
}
// ----
// TypeError: (37-45): Fallback function cannot take parameters.
@@ -1,5 +1,5 @@
library C {
function() external {}
fallback() external {}
}
// ----
// TypeError: (16-38): Libraries cannot have fallback functions.
@@ -0,0 +1,6 @@
library C {
receive() external payable {}
}
// ----
// TypeError: (16-45): Library functions cannot be payable.
// TypeError: (16-45): Libraries cannot have receive ether functions.
@@ -1,5 +1,5 @@
contract C {
function() external returns (uint) { }
fallback() external returns (uint) { }
}
// ----
// TypeError: (45-51): Fallback function cannot return values.
// TypeError: (45-51): Fallback function can only have a single "bytes memory" return value.
@@ -1,7 +1,7 @@
contract C {
uint x;
function() external { x = 2; }
function() external { x = 3; }
fallback() external { x = 2; }
fallback() external { x = 3; }
}
// ----
// DeclarationError: (64-94): Only one fallback function is allowed.
@@ -1,7 +1,7 @@
contract A {
uint x;
function() external { x = 1; }
fallback() external { x = 1; }
}
contract C is A {
function() override external { x = 2; }
fallback() override external { x = 2; }
}
@@ -1,3 +1,3 @@
contract test { function() external { uint x = 1; uint y = 2; x || y; } }
contract test { fallback() external { uint x = 1; uint y = 2; x || y; } }
// ----
// TypeError: (62-68): Operator || not compatible with types uint256 and uint256
@@ -1,3 +1,3 @@
contract test { function() external { uint x = 1; uint y = 2; x && y; } }
contract test { fallback() external { uint x = 1; uint y = 2; x && y; } }
// ----
// TypeError: (62-68): Operator && not compatible with types uint256 and uint256
@@ -1,3 +1,3 @@
contract test { function() external { uint x = 1; !x; } }
contract test { fallback() external { uint x = 1; !x; } }
// ----
// TypeError: (50-52): Unary operator ! cannot be applied to type uint256
@@ -1,3 +1,3 @@
contract test { function() external { uint x = 3; int y = -4; x ** y; } }
contract test { fallback() external { uint x = 3; int y = -4; x ** y; } }
// ----
// TypeError: (62-68): Operator ** not compatible with types uint256 and int256. Exponentiation power is not allowed to be a signed integer type.
@@ -1,5 +1,5 @@
contract test {
function() external { uint x = 3; int y = -4; y ** x; }
fallback() external { uint x = 3; int y = -4; y ** x; }
function f() public pure { int16 x = 3; uint8 y = 4; x ** y; }
function g() public pure { int16 x = 3; uint16 y = 4; x ** y; }
}
@@ -1,3 +1,3 @@
contract test { bytes a; bytes b; function() external { a == b; } }
contract test { bytes a; bytes b; fallback() external { a == b; } }
// ----
// TypeError: (56-62): Operator == not compatible with types bytes storage ref and bytes storage ref
@@ -2,7 +2,7 @@ contract test {
struct s {uint a;}
s x;
s y;
function() external {
fallback() external {
x == y;
}
}
@@ -1,5 +1,5 @@
interface I {
function() external;
fallback() external;
function f() external;
}
// ----
@@ -2,7 +2,7 @@ interface I {
event A();
function f() external;
function g() external;
function() external;
fallback() external;
}
contract C is I {
function f() public override {
@@ -2,13 +2,13 @@
// because A does not have a payable fallback function.
contract A {
function() payable external {}
receive() payable external {}
}
contract B {
A a;
function() external {
fallback() external {
address(a).transfer(100);
}
}
@@ -5,7 +5,7 @@ contract A {
contract B {
A a;
function() external {
fallback() external {
a.transfer();
}
}
@@ -1,3 +1,3 @@
contract C {
function () external { }
fallback () external { }
}
@@ -1,5 +1,5 @@
contract C {
function () internal { }
fallback () internal { }
}
// ----
// TypeError: (17-41): Fallback function must be defined as "external".
@@ -1,5 +1,5 @@
contract C {
function () private { }
fallback () private { }
}
// ----
// TypeError: (17-40): Fallback function must be defined as "external".
@@ -1,5 +1,5 @@
contract C {
function () public { }
fallback () public { }
}
// ----
// TypeError: (17-39): Fallback function must be defined as "external".
@@ -6,7 +6,7 @@ contract C {
function transfer(uint amount) public {
address(this).transfer(amount); // to avoid pureness warning
}
function() payable external {
receive() payable external {
}
}
contract D {
@@ -1,4 +1,4 @@
contract c {
function() external { }
fallback() external { }
}
// ----
@@ -2,4 +2,4 @@ contract test {
function (uint, uint) modifier1() returns (uint) f1;
}
// ----
// ParserError: (66-68): Expected '{' but got identifier
// ParserError: (48-49): Expected ';' but got '('
@@ -0,0 +1,5 @@
contract C {
receive(uint256) external payable {}
}
// ----
// TypeError: (24-33): Receive ether function cannot take parameters.
@@ -0,0 +1,8 @@
contract C {
// Check that visibility is also enforced for the receive ether function.
receive() {}
}
// ----
// SyntaxError: (95-107): No visibility specified. Did you intend to add "external"?
// TypeError: (95-107): Receive ether function must be payable, but is "nonpayable".
// TypeError: (95-107): Receive ether function must be defined as "external".
@@ -0,0 +1,5 @@
contract C {
function() external payable {}
}
// ----
// ParserError: (45-46): Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the "fallback" keyword or the "ether" keyword instead.
@@ -0,0 +1,6 @@
contract C {
uint x;
receive() external pure { x = 2; }
}
// ----
// TypeError: (29-63): Receive ether function must be payable, but is "pure".
@@ -0,0 +1,5 @@
contract C {
function receive() external pure {}
}
// ----
// Warning: (26-33): This function is named "receive" but is not the receive function of the contract. If you intend this to be a receive function, use "receive(...) { ... }" without the "function" keyword to define it.
@@ -0,0 +1,6 @@
contract C {
receive() external returns (uint256) {}
}
// ----
// TypeError: (17-56): Receive ether function must be payable, but is "nonpayable".
// TypeError: (44-53): Receive ether function cannot return values.
@@ -0,0 +1,6 @@
contract C {
uint x;
receive() external view { x = 2; }
}
// ----
// TypeError: (29-63): Receive ether function must be payable, but is "view".
@@ -15,6 +15,6 @@ contract B {
function f() public {
s.a = address(this);
}
function() external payable {
receive() external payable {
}
}
@@ -2,7 +2,8 @@ contract C {
function f() public pure returns (C c) {
c = C(address(2));
}
function() external payable {
fallback() external payable {
}
}
// ----
// Warning: (0-120): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
@@ -0,0 +1,8 @@
contract C {
function f() public pure returns (C c) {
c = C(address(2));
}
receive() external payable {
}
}
// ----
@@ -3,7 +3,7 @@ contract C {
address payable a = address(this);
a;
}
function() external {
fallback() external {
}
}
// ----
@@ -3,7 +3,8 @@ contract C {
address payable a = address(this);
a;
}
function() external payable {
fallback() external payable {
}
}
// ----
// Warning: (0-129): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
@@ -3,8 +3,9 @@ contract C {
address payable a = this;
a;
}
function() external payable {
fallback() external payable {
}
}
// ----
// Warning: (0-120): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
// TypeError: (46-70): Type contract C is not implicitly convertible to expected type address payable.
@@ -0,0 +1,9 @@
contract C {
function f() public view {
address payable a = address(this);
a;
}
receive() external payable {
}
}
// ----
@@ -0,0 +1,10 @@
contract C {
function f() public view {
address payable a = this;
a;
}
receive() external payable {
}
}
// ----
// TypeError: (46-70): Type contract C is not implicitly convertible to expected type address payable.
@@ -3,8 +3,9 @@ contract C {
address a = address(2);
c = C(a);
}
function() external payable {
fallback() external payable {
}
}
// ----
// Warning: (0-139): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
// TypeError: (92-96): Explicit type conversion not allowed from non-payable "address" to "contract C", which has a payable fallback function.
@@ -0,0 +1,10 @@
contract C {
function f() public pure returns (C c) {
address a = address(2);
c = C(a);
}
receive() external payable {
}
}
// ----
// TypeError: (92-96): Explicit type conversion not allowed from non-payable "address" to "contract C", which has a payable fallback function.
@@ -1,6 +1,6 @@
contract n
{
function()
fallback()
{
// Used to cause a segfault
var (x,y) = (1);
@@ -13,5 +13,4 @@ contract n
}
// ----
// SyntaxError: (14-129): No visibility specified. Did you intend to add "external"?
// TypeError: (14-129): Fallback function must be defined as "external".
// TypeError: (60-75): Different number of components on the left hand side (2) than on the right hand side (1).
@@ -16,5 +16,5 @@ contract C {
assert(true);
x; y; z;
}
function() payable external {}
receive() payable external {}
}
@@ -16,7 +16,7 @@ contract C {
(bool success,) = address(this).call("");
require(success);
}
function() payable external {
receive() payable external {
}
}
// ----
@@ -1,6 +1,6 @@
contract C
{
function () external {
fallback() external {
uint x;
assembly {
x := callvalue()

Some files were not shown because too many files have changed in this diff Show More