Fallback function has to be external: backwards-compatible changes.

This commit is contained in:
chriseth
2018-06-29 00:23:52 +02:00
parent 4268062985
commit eeef82b2d7
43 changed files with 123 additions and 105 deletions
@@ -0,0 +1,6 @@
contract C {
// Check that visibility is also enforced for the fallback function.
function() {}
}
// ----
// Warning: (90-103): No visibility specified. Defaulting to "public".
@@ -1,6 +1,6 @@
contract C {
uint x;
function() pure { x = 2; }
function() external pure { x = 2; }
}
// ----
// TypeError: (29-55): Fallback function must be payable or non-payable, but is "pure".
// TypeError: (29-64): Fallback function must be payable or non-payable, but is "pure".
@@ -1,6 +1,6 @@
contract C {
uint x;
function() view { x = 2; }
function() external view { x = 2; }
}
// ----
// TypeError: (29-55): Fallback function must be payable or non-payable, but is "view".
// TypeError: (29-64): Fallback function must be payable or non-payable, but is "view".
@@ -1,4 +1,4 @@
contract C {
uint x;
function() public { x = 2; }
function() external { x = 2; }
}
@@ -1,6 +1,6 @@
contract C {
uint x;
function(uint a) public { x = 2; }
function(uint a) external { x = 2; }
}
// ----
// TypeError: (37-45): Fallback function cannot take parameters.
@@ -1,5 +1,5 @@
library C {
function() public {}
function() external {}
}
// ----
// TypeError: (16-36): Libraries cannot have fallback functions.
// TypeError: (16-38): Libraries cannot have fallback functions.
@@ -1,5 +1,5 @@
contract C {
function() public returns (uint) { }
function() external returns (uint) { }
}
// ----
// TypeError: (43-49): Fallback function cannot return values.
// TypeError: (45-51): Fallback function cannot return values.
@@ -1,7 +1,7 @@
contract C {
uint x;
function() public { x = 2; }
function() public { x = 3; }
function() external { x = 2; }
function() external { x = 3; }
}
// ----
// DeclarationError: (62-90): Only one fallback function is allowed.
// DeclarationError: (64-94): Only one fallback function is allowed.
@@ -1,7 +1,7 @@
contract A {
uint x;
function() public { x = 1; }
function() external { x = 1; }
}
contract C is A {
function() public { x = 2; }
function() external { x = 2; }
}
@@ -1,3 +1,3 @@
contract test { function() public { uint x = 1; uint y = 2; x || y; } }
contract test { function() external { uint x = 1; uint y = 2; x || y; } }
// ----
// TypeError: (60-66): Operator || not compatible with types uint256 and uint256
// TypeError: (62-68): Operator || not compatible with types uint256 and uint256
@@ -1,3 +1,3 @@
contract test { function() public { uint x = 1; uint y = 2; x && y; } }
contract test { function() external { uint x = 1; uint y = 2; x && y; } }
// ----
// TypeError: (60-66): Operator && not compatible with types uint256 and uint256
// TypeError: (62-68): Operator && not compatible with types uint256 and uint256
@@ -1,3 +1,3 @@
contract test { function() public { uint x = 1; !x; } }
contract test { function() external { uint x = 1; !x; } }
// ----
// TypeError: (48-50): Unary operator ! cannot be applied to type uint256
// TypeError: (50-52): Unary operator ! cannot be applied to type uint256
@@ -1,3 +1,3 @@
contract test { function() public { uint x = 3; int y = -4; x ** y; } }
contract test { function() external { uint x = 3; int y = -4; x ** y; } }
// ----
// TypeError: (60-66): Operator ** not compatible with types uint256 and int256
// TypeError: (62-68): Operator ** not compatible with types uint256 and int256
@@ -1,3 +1,3 @@
contract test { function() public { uint x = 3; int y = -4; y ** x; } }
contract test { function() external { uint x = 3; int y = -4; y ** x; } }
// ----
// TypeError: (60-66): Operator ** not compatible with types int256 and uint256
// TypeError: (62-68): Operator ** not compatible with types int256 and uint256
@@ -1,3 +1,3 @@
contract test { function() public { int x = -3; int y = -4; x ** y; } }
contract test { function() external { int x = -3; int y = -4; x ** y; } }
// ----
// TypeError: (60-66): Operator ** not compatible with types int256 and int256
// TypeError: (62-68): Operator ** not compatible with types int256 and int256
@@ -1,3 +1,3 @@
contract test { bytes a; bytes b; function() public { a == b; } }
contract test { bytes a; bytes b; function() external { a == b; } }
// ----
// TypeError: (54-60): Operator == not compatible with types bytes storage ref and bytes storage ref
// TypeError: (56-62): Operator == not compatible with types bytes storage ref and bytes storage ref
@@ -1,3 +1,10 @@
contract test { struct s {uint a;} s x; s y; function() public { x == y; } }
contract test {
struct s {uint a;}
s x;
s y;
function() external {
x == y;
}
}
// ----
// TypeError: (65-71): Operator == not compatible with types struct test.s storage ref and struct test.s storage ref
// TypeError: (79-85): Operator == not compatible with types struct test.s storage ref and struct test.s storage ref
@@ -1,9 +1,5 @@
interface I {
function();
function f();
function() external;
function f() external;
}
// ----
// Warning: (18-29): Functions in interfaces should be declared external.
// Warning: (34-47): Functions in interfaces should be declared external.
// Warning: (18-29): No visibility specified. Defaulting to "public". In interfaces it defaults to external.
// Warning: (34-47): No visibility specified. Defaulting to "public". In interfaces it defaults to external.
@@ -1,17 +1,11 @@
interface I {
event A();
function f();
function g();
function();
function f() external;
function g() external;
function() external;
}
contract C is I {
function f() public {
}
}
// ----
// Warning: (33-46): Functions in interfaces should be declared external.
// Warning: (51-64): Functions in interfaces should be declared external.
// Warning: (69-80): Functions in interfaces should be declared external.
// Warning: (33-46): No visibility specified. Defaulting to "public". In interfaces it defaults to external.
// Warning: (51-64): No visibility specified. Defaulting to "public". In interfaces it defaults to external.
// Warning: (69-80): No visibility specified. Defaulting to "public". In interfaces it defaults to external.
@@ -2,16 +2,16 @@
// because A's fallback function is not payable.
contract A {
function() public {}
function() external {}
}
contract B {
A a;
function() public {
function() external {
a.transfer(100);
}
}
// ----
// Warning: (209-219): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead.
// TypeError: (209-219): Value transfer to a contract without a payable fallback function.
// Warning: (213-223): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead.
// TypeError: (213-223): Value transfer to a contract without a payable fallback function.
@@ -6,10 +6,10 @@ contract A {}
contract B {
A a;
function() public {
function() external {
a.transfer(100);
}
}
// ----
// Warning: (190-200): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead.
// TypeError: (190-200): Value transfer to a contract without a payable fallback function.
// Warning: (192-202): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead.
// TypeError: (192-202): Value transfer to a contract without a payable fallback function.
@@ -2,16 +2,16 @@
// because A does not have a payable fallback function.
contract A {
function() public {}
function() external {}
}
contract B {
A a;
function() public {
function() external {
require(a.send(100));
}
}
// ----
// Warning: (220-226): Using contract member "send" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).send" instead.
// TypeError: (220-226): Value transfer to a contract without a payable fallback function.
// Warning: (224-230): Using contract member "send" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).send" instead.
// TypeError: (224-230): Value transfer to a contract without a payable fallback function.
@@ -2,15 +2,15 @@
// because A does not have a payable fallback function.
contract A {
function() payable public {}
function() payable external {}
}
contract B {
A a;
function() public {
function() external {
a.transfer(100);
}
}
// ----
// Warning: (224-234): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead.
// Warning: (228-238): Using contract member "transfer" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).transfer" instead.
@@ -5,7 +5,7 @@ contract A {
contract B {
A a;
function() public {
function() external {
a.transfer();
}
}
@@ -0,0 +1,3 @@
contract C {
function () external { }
}
@@ -0,0 +1,4 @@
contract C {
function () internal { }
}
// ----
@@ -0,0 +1,4 @@
contract C {
function () private { }
}
// ----
@@ -0,0 +1,4 @@
contract C {
function () public { }
}
// ----
@@ -1,5 +1,4 @@
contract c {
function() { }
function() external { }
}
// ----
// Warning: (17-31): No visibility specified. Defaulting to "public".
@@ -14,5 +14,5 @@ contract C {
assert(true);
x; y; z;
}
function() payable public {}
function() payable external {}
}