Disallow private functions from being overridden

This commit is contained in:
Mathias Baumann 2020-03-09 13:25:26 +01:00 committed by chriseth
parent 9c3226ce75
commit e2db9d7ef3
11 changed files with 73 additions and 1 deletions

View File

@ -1,3 +1,8 @@
### 0.5.17 (2020-03-17)
Bugfixes:
* Type Checker: Disallow overriding of private functions.
### 0.5.16 (2020-01-02)
Bugfixes:

View File

@ -782,6 +782,10 @@
"bugs": [],
"released": "2020-01-02"
},
"0.5.17": {
"bugs": [],
"released": "2020-03-17"
},
"0.5.2": {
"bugs": [
"SignedArrayStorageCopy",

View File

@ -203,6 +203,9 @@ void ContractLevelChecker::checkFunctionOverride(FunctionDefinition const& _func
stateMutabilityToString(_function.stateMutability()) +
"\"."
);
if (_super.visibility() == Declaration::Visibility::Private)
overrideError(_function, _super, "Private functions cannot be overridden.");
}
void ContractLevelChecker::overrideError(FunctionDefinition const& function, FunctionDefinition const& super, string message)

View File

@ -31,7 +31,7 @@ function test_fn { npm run test; }
function zeppelin_test
{
OPTIMIZER_LEVEL=1
setup https://github.com/OpenZeppelin/openzeppelin-solidity.git master
setup https://github.com/OpenZeppelin/openzeppelin-solidity.git v2.5.0
run_install install_fn
CONFIG="truffle-config.js"

View File

@ -0,0 +1,8 @@
contract A {
function test() private returns (uint256) {}
}
contract X is A {
function test() private returns (uint256) {}
}
// ----
// TypeError: (80-124): Private functions cannot be overridden.

View File

@ -0,0 +1,8 @@
contract A {
function test() public returns (uint256) {}
}
contract X is A {
function test() private returns (uint256) {}
}
// ----
// TypeError: (79-123): Overriding function visibility differs.

View File

@ -0,0 +1,9 @@
contract A {
function test() private returns (uint256) {}
}
contract X is A {
function test() public returns (uint256) {}
}
// ----
// TypeError: (80-123): Overriding function visibility differs.
// TypeError: (80-123): Private functions cannot be overridden.

View File

@ -0,0 +1,11 @@
contract A {
function test() private returns (uint256) {}
}
contract B {
function test() private returns (uint256) {}
}
contract X is A, B {
}
// ----
// TypeError: (75-119): Private functions cannot be overridden.

View File

@ -0,0 +1,11 @@
contract A {
function test() public returns (uint256) {}
}
contract B {
function test() private returns (uint256) {}
}
contract X is A, B {
}
// ----
// TypeError: (74-118): Overriding function visibility differs.

View File

@ -0,0 +1,12 @@
contract A {
function test() private returns (uint256) {}
}
contract B {
function test() public returns (uint256) {}
}
contract X is A, B {
}
// ----
// TypeError: (75-118): Overriding function visibility differs.
// TypeError: (75-118): Private functions cannot be overridden.

View File

@ -58,6 +58,7 @@ DIR=$(mktemp -d)
npm version --allow-same-version --no-git-tag-version $VERSION
echo "Running solc-js tests..."
sed -i -e 's/latest/v0.5.0+commit.1d4f565a/' test/package.js
npm run test
)
rm -rf "$DIR"