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
@@ -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".