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:
@@ -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.
|
||||
+8
@@ -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.
|
||||
+4
@@ -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; } }
|
||||
|
||||
+8
@@ -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 {}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
fallback() external {}
|
||||
}
|
||||
contract D is C {
|
||||
}
|
||||
contract E is D {
|
||||
fallback() override external {}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
fallback() external {}
|
||||
}
|
||||
contract D is C {
|
||||
fallback() external {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (58-80): Overriding function is missing 'override' specifier.
|
||||
+10
@@ -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.
|
||||
+8
@@ -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 {}
|
||||
}
|
||||
+8
@@ -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.
|
||||
+10
@@ -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
-1
@@ -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
-1
@@ -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.
|
||||
+2
-2
@@ -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.
|
||||
|
||||
+2
-2
@@ -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
-1
@@ -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
-1
@@ -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
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -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
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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".
|
||||
|
||||
+1
-1
@@ -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 { }
|
||||
}
|
||||
// ----
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
+1
-1
@@ -3,7 +3,7 @@ contract C {
|
||||
address payable a = address(this);
|
||||
a;
|
||||
}
|
||||
function() external {
|
||||
fallback() external {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
|
||||
+2
-1
@@ -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.
|
||||
|
||||
+2
-1
@@ -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 {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
+10
@@ -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.
|
||||
+2
-1
@@ -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
-1
@@ -1,6 +1,6 @@
|
||||
contract C
|
||||
{
|
||||
function () external {
|
||||
fallback() external {
|
||||
uint x;
|
||||
assembly {
|
||||
x := callvalue()
|
||||
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
contract C
|
||||
{
|
||||
function () external payable {
|
||||
receive () external payable {
|
||||
}
|
||||
fallback () external payable {
|
||||
uint x;
|
||||
assembly {
|
||||
x := callvalue()
|
||||
|
||||
Reference in New Issue
Block a user