mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10214 from ethereum/fallbackReturn
Allow fallback function to return data.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
contract A {
|
||||
uint public x;
|
||||
fallback () external {
|
||||
if (x == 2) return;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// ()
|
||||
// x() -> 1
|
||||
// ()
|
||||
// x() -> 2
|
||||
// ()
|
||||
// x() -> 2
|
||||
// ()
|
||||
// x() -> 2
|
||||
@@ -0,0 +1,17 @@
|
||||
contract A {
|
||||
uint public x;
|
||||
fallback (bytes calldata _input) external returns (bytes memory) {
|
||||
x = _input.length;
|
||||
return "";
|
||||
}
|
||||
function f() public returns (bool, bytes memory) {
|
||||
(bool success, bytes memory retval) = address(this).call("abc");
|
||||
return (success, retval);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f() -> 0x01, 0x40, 0x00
|
||||
// x() -> 3
|
||||
@@ -0,0 +1,16 @@
|
||||
contract A {
|
||||
bytes public x;
|
||||
fallback (bytes calldata _input) external returns (bytes memory) {
|
||||
x = _input;
|
||||
return "";
|
||||
}
|
||||
function f() public returns (bool, bytes memory) {
|
||||
(bool success, bytes memory retval) = address(this).call("abc");
|
||||
return (success, retval);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f() -> 0x01, 0x40, 0x00
|
||||
// x() -> 0x20, 3, "abc"
|
||||
@@ -0,0 +1,19 @@
|
||||
contract A {
|
||||
fallback (bytes calldata _input) virtual external returns (bytes memory) {
|
||||
return _input;
|
||||
}
|
||||
}
|
||||
contract B is A {
|
||||
fallback (bytes calldata _input) override external returns (bytes memory) {
|
||||
return "xyz";
|
||||
}
|
||||
function f() public returns (bool, bytes memory) {
|
||||
(bool success, bytes memory retval) = address(this).call("abc");
|
||||
return (success, retval);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x01, 0x40, 0x03, 0x78797a0000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,18 @@
|
||||
contract A {
|
||||
fallback (bytes calldata _input) virtual external returns (bytes memory) {
|
||||
return _input;
|
||||
}
|
||||
}
|
||||
contract B is A {
|
||||
fallback () override external {
|
||||
}
|
||||
function f() public returns (bool, bytes memory) {
|
||||
(bool success, bytes memory retval) = address(this).call("abc");
|
||||
return (success, retval);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 1, 0x40, 0x00
|
||||
@@ -0,0 +1,22 @@
|
||||
contract A {
|
||||
fallback (bytes calldata _input) virtual external returns (bytes memory) {
|
||||
return _input;
|
||||
}
|
||||
}
|
||||
contract B {
|
||||
fallback (bytes calldata _input) virtual external returns (bytes memory) {
|
||||
return "xyz";
|
||||
}
|
||||
}
|
||||
contract C is B, A {
|
||||
fallback () external override (B, A) {}
|
||||
function f() public returns (bool, bytes memory) {
|
||||
(bool success, bytes memory retval) = address(this).call("abc");
|
||||
return (success, retval);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x01, 0x40, 0x00
|
||||
@@ -0,0 +1,14 @@
|
||||
contract A {
|
||||
fallback (bytes calldata _input) external returns (bytes memory) {
|
||||
return _input;
|
||||
}
|
||||
function f() public returns (bool, bytes memory) {
|
||||
(bool success, bytes memory retval) = address(this).call("abc");
|
||||
return (success, retval);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f() -> 0x01, 0x40, 0x03, 0x6162630000000000000000000000000000000000000000000000000000000000
|
||||
@@ -2,4 +2,4 @@ contract C {
|
||||
fallback(uint256) external {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 3978: (25-34): Fallback function cannot take parameters.
|
||||
// TypeError 5570: (44-44): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
fallback(bytes calldata _input) external returns (bytes memory _output) {}
|
||||
fallback() external {}
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7301: (96-118): Only one fallback function is allowed.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
fallback(bytes calldata _input) external returns (bytes memory _output) {}
|
||||
}
|
||||
contract D is C {
|
||||
fallback() external {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9456: (116-138): Overriding function is missing "override" specifier.
|
||||
// TypeError 4334: (17-91): Trying to override non-virtual function. Did you forget to add "virtual"?
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
fallback(bytes calldata _input) external virtual returns (bytes memory _output) {}
|
||||
}
|
||||
contract D is C {
|
||||
fallback() external override {}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,13 @@
|
||||
contract D {
|
||||
fallback(bytes memory) external returns (bytes memory) {}
|
||||
}
|
||||
contract E {
|
||||
fallback(bytes memory) external returns (bytes calldata) {}
|
||||
}
|
||||
contract F {
|
||||
fallback(bytes calldata) external returns (bytes calldata) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 5570: (57-71): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
// TypeError 5570: (134-150): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
// TypeError 5570: (215-231): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
@@ -0,0 +1,20 @@
|
||||
contract A {
|
||||
fallback (bytes calldata _input) external returns (bytes memory) {
|
||||
return _input;
|
||||
}
|
||||
}
|
||||
contract B {
|
||||
fallback (bytes calldata _input) external returns (bytes memory) {
|
||||
return "xyz";
|
||||
}
|
||||
}
|
||||
contract C is B, A {
|
||||
function f() public returns (bool, bytes memory) {
|
||||
(bool success, bytes memory retval) = address(this).call("abc");
|
||||
return (success, retval);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// TypeError 6480: (229-420): Derived contract must override function "". Two or more base classes define function with same name and parameter types.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
fallback() external returns (bytes memory _output) {}
|
||||
}
|
||||
contract D {
|
||||
fallback(bytes calldata _input) external {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 5570: (45-67): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
// TypeError 5570: (131-131): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
@@ -2,4 +2,4 @@ contract C {
|
||||
fallback() external returns (bytes memory, bytes memory) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 5570: (45-73): Fallback function can only have a single "bytes memory" return value.
|
||||
// TypeError 5570: (45-73): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
|
||||
@@ -2,4 +2,4 @@ contract C {
|
||||
fallback() external returns (uint256) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 5570: (45-54): Fallback function can only have a single "bytes memory" return value.
|
||||
// TypeError 5570: (45-54): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
|
||||
@@ -2,4 +2,4 @@ contract C {
|
||||
fallback() external returns (bytes memory) {}
|
||||
}
|
||||
// ----
|
||||
// TypeError 6151: (45-59): Return values for fallback functions are not yet implemented.
|
||||
// TypeError 5570: (45-59): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
contract C {
|
||||
fallback(bytes calldata _input) external returns (bytes memory _output) {}
|
||||
}
|
||||
// ----
|
||||
+1
-1
@@ -3,4 +3,4 @@ contract C {
|
||||
fallback(uint a) external { x = 2; }
|
||||
}
|
||||
// ----
|
||||
// TypeError 3978: (37-45): Fallback function cannot take parameters.
|
||||
// TypeError 5570: (55-55): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ contract C {
|
||||
fallback() external returns (uint) { }
|
||||
}
|
||||
// ----
|
||||
// TypeError 5570: (45-51): Fallback function can only have a single "bytes memory" return value.
|
||||
// TypeError 5570: (45-51): Fallback function either has to have the signature "fallback()" or "fallback(bytes calldata) returns (bytes memory)".
|
||||
|
||||
Reference in New Issue
Block a user