Merge pull request #12604 from ethereum/develop

Merge develop into breaking
This commit is contained in:
chriseth
2022-01-31 17:59:03 +01:00
committed by GitHub
206 changed files with 3675 additions and 1271 deletions
@@ -1,3 +1,4 @@
int[L] constant L = 6;
// ----
// TypeError 5462: (4-5): Invalid array length, expected integer literal or constant expression.
// TypeError 9259: (0-21): Only constants of value type and byte array type are implemented.
@@ -3,3 +3,4 @@ contract C {
}
// ----
// TypeError 5462: (21-22): Invalid array length, expected integer literal or constant expression.
// TypeError 9259: (17-38): Only constants of value type and byte array type are implemented.
@@ -1,3 +1,3 @@
mapping(uint => uint) constant b = b;
// ----
// DeclarationError 3530: (0-36): The type contains a (nested) mapping and therefore cannot be a constant.
// TypeError 9259: (0-36): Only constants of value type and byte array type are implemented.
@@ -1,4 +1,4 @@
struct S { uint x; }
S constant s;
// ----
// TypeError 9259: (21-33): Constants of non-value type not yet implemented.
// TypeError 9259: (21-33): Only constants of value type and byte array type are implemented.
@@ -1,5 +1,5 @@
contract C {
modifier revertIfNoReturn() {
modifier alwaysRevert() {
_;
revert();
}
@@ -9,10 +9,10 @@ contract C {
}
struct S { uint a; }
S s;
function f(bool flag) revertIfNoReturn() internal view {
function f(bool flag) alwaysRevert() internal view {
if (flag) s;
}
function g(bool flag) revertIfNoReturn() ifFlag(flag) internal view {
function g(bool flag) alwaysRevert() ifFlag(flag) internal view {
s;
}
@@ -0,0 +1,12 @@
contract A {
function f() mod internal returns (uint[] storage) {
revert();
}
function g() mod internal returns (uint[] storage) {
}
modifier mod() virtual {
_;
}
}
// ----
// TypeError 3464: (118-132): This variable is of storage pointer type and can be returned without prior assignment, which would lead to undefined behaviour.
@@ -0,0 +1,17 @@
contract A {
function f() mod internal returns (uint[] storage) {
}
modifier mod() virtual {
revert();
_;
}
}
contract B is A {
modifier mod() override { _; }
function g() public {
f()[0] = 42;
}
}
// ----
// Warning 5740: (65-69): Unreachable code.
// TypeError 3464: (49-63): This variable is of storage pointer type and can be returned without prior assignment, which would lead to undefined behaviour.
@@ -1,5 +1,5 @@
contract C {
modifier revertIfNoReturn() {
modifier callAndRevert() {
_;
revert();
}
@@ -13,10 +13,10 @@ contract C {
return s;
}
function g(bool flag) ifFlag(flag) revertIfNoReturn() internal view returns(S storage) {
function g(bool flag) ifFlag(flag) callAndRevert() internal view returns(S storage) {
return s;
}
}
// ----
// TypeError 3464: (249-258): This variable is of storage pointer type and can be returned without prior assignment, which would lead to undefined behaviour.
// TypeError 3464: (367-376): This variable is of storage pointer type and can be returned without prior assignment, which would lead to undefined behaviour.
// TypeError 3464: (246-255): This variable is of storage pointer type and can be returned without prior assignment, which would lead to undefined behaviour.
// TypeError 3464: (361-370): This variable is of storage pointer type and can be returned without prior assignment, which would lead to undefined behaviour.
@@ -1,5 +1,5 @@
contract C {
modifier revertIfNoReturn() {
modifier callAndRevert() {
_;
revert();
}
@@ -9,10 +9,10 @@ contract C {
}
struct S { uint a; }
S s;
function f(bool flag) revertIfNoReturn() internal view returns(S storage) {
function f(bool flag) callAndRevert() internal view returns(S storage) {
if (flag) return s;
}
function g(bool flag) revertIfNoReturn() ifFlag(flag) internal view returns(S storage) {
function g(bool flag) callAndRevert() ifFlag(flag) internal view returns(S storage) {
return s;
}
@@ -0,0 +1,12 @@
contract C {
function external_test_function() external {}
function comparison_operator_for_external_function_with_extra_slots() external returns (bool) {
return (
(this.external_test_function{gas: 4} == this.external_test_function) &&
(this.external_test_function{gas: 4} == this.external_test_function{gas: 4})
);
}
}
// ----
// TypeError 2271: (193-259): Operator == not compatible with types function () external and function () external
// TypeError 2271: (277-351): Operator == not compatible with types function () external and function () external
@@ -0,0 +1,23 @@
contract C {
function external_test_function() external {}
function internal_test_function() internal {}
function comparison_operator_between_internal_and_external_function_pointers() external returns (bool) {
function () external external_function_pointer_local = this.external_test_function;
function () internal internal_function_pointer_local = internal_test_function;
assert(
this.external_test_function == external_function_pointer_local &&
internal_function_pointer_local == internal_test_function
);
assert(
internal_function_pointer_local != external_function_pointer_local &&
internal_test_function != this.external_test_function
);
return true;
}
}
// ----
// TypeError 2271: (606-672): Operator != not compatible with types function () and function () external
// TypeError 2271: (688-741): Operator != not compatible with types function () and function () external
@@ -0,0 +1,26 @@
contract C {
function external_test_function1(uint num) external {}
function external_test_function2(bool val) external {}
function comparison_operator_between_internal_and_external_function_pointers() external returns (bool) {
function () external external_function_pointer_local1 = this.external_test_function1;
function () external external_function_pointer_local2 = this.external_test_function2;
assert(
this.external_test_function1 == external_function_pointer_local1 &&
this.external_test_function2 == external_function_pointer_local2
);
assert(
external_function_pointer_local2 != external_function_pointer_local1 &&
this.external_test_function2 != this.external_test_function1
);
return true;
}
}
// ----
// TypeError 9574: (249-333): Type function (uint256) external is not implicitly convertible to expected type function () external.
// TypeError 9574: (343-427): Type function (bool) external is not implicitly convertible to expected type function () external.
// TypeError 2271: (458-522): Operator == not compatible with types function (uint256) external and function () external
// TypeError 2271: (538-602): Operator == not compatible with types function (bool) external and function () external
// TypeError 2271: (726-786): Operator != not compatible with types function (bool) external and function (uint256) external
@@ -0,0 +1,8 @@
contract C {
function f (address) external returns (bool) {
this.f{gas: 42}.address;
}
}
// ----
// Warning 6321: (56-60): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
// Warning 2018: (17-102): Function state mutability can be restricted to view
@@ -5,4 +5,4 @@ contract C {
S public constant e = 0x1212121212121212121212121212121212121212;
}
// ----
// DeclarationError 3530: (71-135): The type contains a (nested) mapping and therefore cannot be a constant.
// TypeError 9259: (71-135): Only constants of value type and byte array type are implemented.
@@ -0,0 +1,10 @@
contract Parent {
constructor() {
return;
}
}
contract Child is Parent {
uint public immutable baked = 123;
}
@@ -0,0 +1,9 @@
contract C {
function f() public pure {
function() external g;
assembly {
g.address := 0x42
g.selector := 0x23
}
}
}
@@ -3,3 +3,4 @@ contract test {
}
// ----
// DeclarationError 1788: (31-55): The "constant" keyword can only be used for state variables or variables at file level.
// TypeError 9259: (31-55): Only constants of value type and byte array type are implemented.
@@ -2,4 +2,4 @@ contract C {
uint[3] constant x = [uint(1), 2, 3];
}
// ----
// TypeError 9259: (17-53): Constants of non-value type not yet implemented.
// TypeError 9259: (17-53): Only constants of value type and byte array type are implemented.
@@ -3,4 +3,4 @@ contract C {
S constant x = S(5, new uint[](4));
}
// ----
// TypeError 9259: (52-86): Constants of non-value type not yet implemented.
// TypeError 9259: (52-86): Only constants of value type and byte array type are implemented.
@@ -0,0 +1,4 @@
S constant x;
struct S { int y; }
// ----
// TypeError 9259: (0-12): Only constants of value type and byte array type are implemented.
@@ -2,4 +2,4 @@ contract C {
mapping(uint => uint) constant x;
}
// ----
// DeclarationError 3530: (17-49): The type contains a (nested) mapping and therefore cannot be a constant.
// TypeError 9259: (17-49): Only constants of value type and byte array type are implemented.
@@ -5,4 +5,4 @@ contract C {
S public constant c;
}
// ----
// DeclarationError 3530: (71-90): The type contains a (nested) mapping and therefore cannot be a constant.
// TypeError 9259: (71-90): Only constants of value type and byte array type are implemented.
@@ -3,3 +3,4 @@ contract Foo {
}
// ----
// DeclarationError 1788: (30-55): The "constant" keyword can only be used for state variables or variables at file level.
// TypeError 9259: (30-55): Only constants of value type and byte array type are implemented.
@@ -2,81 +2,47 @@ interface I {
function fExternal(uint256 p, string memory t) external;
}
library L {
function fExternal(uint256 p, string memory t) external {}
contract Other {
function fExternal(uint) external pure {}
function fPublic(uint) public pure {}
function fInternal(uint) internal pure {}
}
contract C {
using L for uint256;
library L {
function fExternal(uint256 p, string memory t) external {}
function fInternal(uint256 p, string memory t) internal {}
}
contract Base {
function baseFunctionExternal(uint) external pure {}
}
contract C is Base {
function f(int a) public {}
function f2(int a, string memory b) public {}
function f3(int a, int b) public {}
function f4() public {}
function fInternal(uint256 p, string memory t) internal {}
function failFunctionArgsWrongType() public returns(bytes memory) {
return abi.encodeCall(this.f, ("test"));
}
function failFunctionArgsTooMany() public returns(bytes memory) {
return abi.encodeCall(this.f, (1, 2));
}
function failFunctionArgsTooFew0() public returns(bytes memory) {
return abi.encodeCall(this.f, ());
}
function failFunctionArgsTooFew1() public returns(bytes memory) {
return abi.encodeCall(this.f);
}
function failFunctionPtrMissing() public returns(bytes memory) {
return abi.encodeCall(1, this.f);
}
function failFunctionPtrWrongType() public returns(bytes memory) {
return abi.encodeCall(abi.encodeCall, (1, 2, 3, "test"));
}
function failFunctionInternal() public returns(bytes memory) {
return abi.encodeCall(fInternal, (1, "123"));
}
function failFunctionInternalFromVariable() public returns(bytes memory) {
function(uint256, string memory) internal localFunctionPointer = fInternal;
return abi.encodeCall(localFunctionPointer, (1, "123"));
}
function failFunctionArgsArrayLiteral() public returns(bytes memory) {
return abi.encodeCall(this.f3, [1, 2]);
}
function failLibraryPointerCall() public returns (bytes memory) {
return abi.encodeCall(L.fExternal, (1, "123"));
}
function failBoundLibraryPointerCall() public returns (bytes memory) {
uint256 x = 1;
return abi.encodeCall(x.fExternal, (1, "123"));
}
function failInterfacePointerCall() public returns (bytes memory) {
return abi.encodeCall(I.fExternal, (1, "123"));
}
function successFunctionArgsIntLiteralTuple() public returns(bytes memory) {
function successFunctionArgsIntLiteralTuple() public view returns(bytes memory) {
return abi.encodeCall(this.f, (1));
}
function successFunctionArgsIntLiteral() public returns(bytes memory) {
function successFunctionArgsIntLiteral() public view returns(bytes memory) {
return abi.encodeCall(this.f, 1);
}
function successFunctionArgsLiteralTuple() public returns(bytes memory) {
function successFunctionArgsLiteralTuple() public view returns(bytes memory) {
return abi.encodeCall(this.f2, (1, "test"));
}
function successFunctionArgsEmptyTuple() public returns(bytes memory) {
function successFunctionArgsEmptyTuple() public view returns(bytes memory) {
return abi.encodeCall(this.f4, ());
}
function viaDeclaration() public pure returns (bytes memory) {
return bytes.concat(
abi.encodeCall(Other.fExternal, (1)),
abi.encodeCall(Other.fPublic, (1)),
abi.encodeCall(I.fExternal, (1, "123"))
);
}
function viaBaseDeclaration() public pure returns (bytes memory) {
return abi.encodeCall(Base.baseFunctionExternal, (1));
}
}
// ----
// TypeError 5407: (486-494): Cannot implicitly convert component at position 0 from "literal_string "test"" to "int256".
// TypeError 7788: (576-606): Expected 1 instead of 2 components for the tuple parameter.
// TypeError 7788: (687-713): Expected 1 instead of 0 components for the tuple parameter.
// TypeError 6219: (794-816): Expected two arguments: a function pointer followed by a tuple.
// TypeError 5511: (911-912): Expected first argument to be a function pointer, not "int_const 1".
// TypeError 3509: (1018-1032): Function must be "public" or "external".
// TypeError 3509: (1145-1154): Function must be "public" or "external". Did you forget to prefix "this."?
// TypeError 3509: (1350-1370): Function must be "public" or "external".
// TypeError 7515: (1469-1500): Expected a tuple with 2 components instead of a single non-tuple parameter.
// TypeError 5407: (1493-1499): Cannot implicitly convert component at position 0 from "uint8[2]" to "int256".
// TypeError 3509: (1596-1607): Function must be "public" or "external".
// TypeError 3509: (1738-1749): Function must be "public" or "external".
// TypeError 3509: (1860-1871): Function must be "public" or "external".
@@ -0,0 +1,27 @@
contract C {
function f(int a) public {}
function f3(int a, int b) public {}
function failFunctionArgsWrongType() public returns(bytes memory) {
return abi.encodeCall(this.f, ("test"));
}
function failFunctionArgsTooMany() public returns(bytes memory) {
return abi.encodeCall(this.f, (1, 2));
}
function failFunctionArgsTooFew0() public returns(bytes memory) {
return abi.encodeCall(this.f, ());
}
function failFunctionArgsTooFew1() public returns(bytes memory) {
return abi.encodeCall(this.f);
}
function failFunctionArgsArrayLiteral() public returns(bytes memory) {
return abi.encodeCall(this.f3, [1, 2]);
}
}
// ----
// TypeError 5407: (181-189): Cannot implicitly convert component at position 0 from "literal_string "test"" to "int256".
// TypeError 7788: (271-301): Expected 1 instead of 2 components for the tuple parameter.
// TypeError 7788: (382-408): Expected 1 instead of 0 components for the tuple parameter.
// TypeError 6219: (489-511): Expected two arguments: a function pointer followed by a tuple.
// TypeError 7515: (597-628): Expected a tuple with 2 components instead of a single non-tuple parameter.
// TypeError 5407: (621-627): Cannot implicitly convert component at position 0 from "uint8[2]" to "int256".
@@ -0,0 +1,78 @@
interface I {
function fExternal(uint256 p, string memory t) external;
}
contract Other {
function fExternal(uint) external pure {}
function fPublic(uint) public pure {}
function fInternal(uint) internal pure {}
}
library L {
function fExternal(uint256 p, string memory t) external {}
function fInternal(uint256 p, string memory t) internal {}
}
contract Base {
function baseFunctionInternal(uint) internal pure {}
function baseFunctionPublic(uint) public pure {}
}
function fileLevel(uint) pure {}
contract C is Base {
using L for uint256;
function fPublic(int a) public {}
function fInternal(uint256 p, string memory t) internal {}
function failFunctionPtrMissing() public returns(bytes memory) {
return abi.encodeCall(1, this.fPublic);
}
function failFunctionPtrWrongType() public returns(bytes memory) {
return abi.encodeCall(abi.encodeCall, (1, 2, 3, "test"));
}
function failFunctionInternal() public returns(bytes memory) {
return abi.encodeCall(fInternal, (1, "123"));
}
function failFunctionInternalFromVariable() public returns(bytes memory) {
function(uint256, string memory) internal localFunctionPointer = fInternal;
return abi.encodeCall(localFunctionPointer, (1, "123"));
}
function failLibraryPointerCall() public {
abi.encodeCall(L.fInternal, (1, "123"));
abi.encodeCall(L.fExternal, (1, "123"));
}
function failBoundLibraryPointerCall() public returns (bytes memory) {
uint256 x = 1;
return abi.encodeCall(x.fExternal, (1, "123"));
}
function viaBaseDeclaration() public pure returns (bytes memory) {
return abi.encodeCall(C.fPublic, (2));
}
function viaBaseDeclaration2() public pure returns (bytes memory) {
return bytes.concat(
abi.encodeCall(Base.baseFunctionPublic, (1)),
abi.encodeCall(Base.baseFunctionInternal, (1))
);
}
function fileLevelFunction() public pure returns (bytes memory) {
return abi.encodeCall(fileLevel, (2));
}
function createFunction() public pure returns (bytes memory) {
return abi.encodeCall(new Other, (2));
}
}
// ----
// TypeError 5511: (742-743): Expected first argument to be a function pointer, not "int_const 1".
// TypeError 3509: (855-869): Expected regular external function type, or external view on public function. Cannot use special function.
// TypeError 3509: (982-991): Expected regular external function type, or external view on public function. Provided internal function.
// TypeError 3509: (1187-1207): Expected regular external function type, or external view on public function. Provided internal function.
// TypeError 3509: (1286-1297): Expected regular external function type, or external view on public function. Provided internal function.
// TypeError 3509: (1329-1340): Expected regular external function type, or external view on public function. Cannot use library functions for abi.encodeCall.
// TypeError 3509: (1471-1482): Expected regular external function type, or external view on public function. Cannot use library functions for abi.encodeCall.
// TypeError 3509: (1592-1601): Expected regular external function type, or external view on public function. Provided internal function. Did you forget to prefix "this."?
// TypeError 3509: (1722-1745): Expected regular external function type, or external view on public function. Provided internal function. Functions from base contracts have to be external.
// TypeError 3509: (1771-1796): Expected regular external function type, or external view on public function. Provided internal function. Functions from base contracts have to be external.
// TypeError 3509: (1902-1911): Expected regular external function type, or external view on public function. Provided internal function.
// TypeError 3509: (2010-2019): Expected regular external function type, or external view on public function. Provided creation function.