More strict override check for data locations.

This commit is contained in:
chriseth
2022-05-17 13:02:12 +02:00
parent bef348aa6a
commit dfa0bcf760
13 changed files with 165 additions and 11 deletions
@@ -0,0 +1,18 @@
abstract contract A {
function f(uint256[] calldata a) external virtual returns (uint256[] calldata);
}
contract B is A {
function f(uint256[] memory a) public override returns (uint256[] memory) {
return a;
}
function g(uint[] calldata x) public returns (uint256[] memory) {
return f(x);
}
}
// ====
// compileViaYul: also
// ----
// f(uint256[]): 0x20, 2, 9, 8 -> 0x20, 2, 9, 8
// g(uint256[]): 0x20, 2, 9, 8 -> 0x20, 2, 9, 8
@@ -0,0 +1,14 @@
abstract contract A {
function f(uint256[1] memory a) external virtual returns (uint256);
}
contract B is A {
function f(uint256[1] calldata a) external pure virtual override returns (uint256) {
return a[0];
}
}
contract C is A, B {
function f(uint256[1] memory a) external pure override(B, A) returns (uint256) {
return a[0];
}
}
// ----
@@ -0,0 +1,13 @@
abstract contract A {
modifier m(uint256[1] memory a) virtual;
function test(uint256[1] memory a) m(a) external {
}
}
contract B is A {
modifier m(uint256[1] calldata a) override {
_;
}
}
// ----
// TypeError 1078: (153-214): Override changes modifier signature.
@@ -0,0 +1,11 @@
abstract contract A {
function f(uint256[1] calldata a) public virtual returns (uint256);
}
contract B is A {
function f(uint256[1] memory a) public override returns (uint256) {
return a[0];
}
}
// ----
// TypeError 7723: (119-213): Data locations of parameters have to be the same when overriding non-external functions, but they differ.
@@ -0,0 +1,16 @@
abstract contract A {
function f(uint256[1] memory a) internal virtual returns (uint256);
function test() external returns (uint) {
uint[1] memory t;
t[0] = 7;
return f(t);
}
}
contract B is A {
function f(uint256[1] calldata a) internal override returns (uint256) {
return a[0];
}
}
// ----
// TypeError 7723: (236-334): Data locations of parameters have to be the same when overriding non-external functions, but they differ.
@@ -0,0 +1,16 @@
abstract contract A {
function f(uint256[1] memory a) public virtual returns (uint256);
function test() external returns (uint) {
uint[1] memory t;
t[0] = 7;
return f(t);
}
}
contract B is A {
function f(uint256[1] calldata a) public override returns (uint256) {
return a[0];
}
}
// ----
// TypeError 7723: (234-330): Data locations of parameters have to be the same when overriding non-external functions, but they differ.
@@ -0,0 +1,7 @@
abstract contract A {
function foo() external virtual view returns(uint[] calldata);
}
contract X is A {
function foo() public view override returns(uint[] memory) { }
}
// ----
@@ -0,0 +1,8 @@
abstract contract A {
function foo() public virtual view returns(uint[] calldata);
}
contract X is A {
function foo() public view override returns(uint[] memory) { }
}
// ----
// TypeError 1443: (105-168): Data locations of return variables have to be the same when overriding non-external functions, but they differ.