diff --git a/Changelog.md b/Changelog.md index 72461f021..e7a43645c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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: diff --git a/docs/bugs_by_version.json b/docs/bugs_by_version.json index a9ce0be92..00bca1f3b 100644 --- a/docs/bugs_by_version.json +++ b/docs/bugs_by_version.json @@ -782,6 +782,10 @@ "bugs": [], "released": "2020-01-02" }, + "0.5.17": { + "bugs": [], + "released": "2020-03-17" + }, "0.5.2": { "bugs": [ "SignedArrayStorageCopy", diff --git a/libsolidity/analysis/ContractLevelChecker.cpp b/libsolidity/analysis/ContractLevelChecker.cpp index 95626bb2a..57ca62fec 100644 --- a/libsolidity/analysis/ContractLevelChecker.cpp +++ b/libsolidity/analysis/ContractLevelChecker.cpp @@ -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) diff --git a/test/externalTests/zeppelin.sh b/test/externalTests/zeppelin.sh index aa784c6ad..2eb467acd 100755 --- a/test/externalTests/zeppelin.sh +++ b/test/externalTests/zeppelin.sh @@ -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" diff --git a/test/libsolidity/syntaxTests/inheritance/override/override_private.sol b/test/libsolidity/syntaxTests/inheritance/override/override_private.sol new file mode 100644 index 000000000..f5e33db4c --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/override/override_private.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/inheritance/override/override_private1.sol b/test/libsolidity/syntaxTests/inheritance/override/override_private1.sol new file mode 100644 index 000000000..127aee556 --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/override/override_private1.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/inheritance/override/override_private2.sol b/test/libsolidity/syntaxTests/inheritance/override/override_private2.sol new file mode 100644 index 000000000..98d687f51 --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/override/override_private2.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/inheritance/override/override_private_multi.sol b/test/libsolidity/syntaxTests/inheritance/override/override_private_multi.sol new file mode 100644 index 000000000..1a159477a --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/override/override_private_multi.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/inheritance/override/override_private_multi1.sol b/test/libsolidity/syntaxTests/inheritance/override/override_private_multi1.sol new file mode 100644 index 000000000..efedd5b92 --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/override/override_private_multi1.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/inheritance/override/override_private_multi2.sol b/test/libsolidity/syntaxTests/inheritance/override/override_private_multi2.sol new file mode 100644 index 000000000..5825b8a79 --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/override/override_private_multi2.sol @@ -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. diff --git a/test/solcjsTests.sh b/test/solcjsTests.sh index d525a3f21..5c918de29 100755 --- a/test/solcjsTests.sh +++ b/test/solcjsTests.sh @@ -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"