From 6f8b5fe53b1e28191cbbc17fd8db499890b2abfb Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Wed, 3 Jun 2020 13:53:11 +0200 Subject: [PATCH] Disallow override with non-public state variables --- Changelog.md | 1 + libsolidity/analysis/OverrideChecker.cpp | 5 +++++ .../inheritance/override/private_state_variable.sol | 9 +++++++++ 3 files changed, 15 insertions(+) create mode 100644 test/libsolidity/syntaxTests/inheritance/override/private_state_variable.sol diff --git a/Changelog.md b/Changelog.md index ec12a214b..a1592946b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -23,6 +23,7 @@ Bugfixes: * Type Checker: Fix internal compiler error when trying to decode too large static arrays. * Type Checker: Fix wrong compiler error when referencing an overridden function without calling it. * Type Checker: Fix internal compiler error when forward referencing non-literal constants from inline assembly. + * Type Checker: Disallow usage of override with non-public state variables. * NatSpec: DocString block is terminated when encountering an empty line. * Scanner: Fix bug when two empty NatSpec comments lead to scanning past EOL. * Code Generator: Trigger proper unimplemented errors on certain array copy operations. diff --git a/libsolidity/analysis/OverrideChecker.cpp b/libsolidity/analysis/OverrideChecker.cpp index 4b9a3b7f3..89f9a6637 100644 --- a/libsolidity/analysis/OverrideChecker.cpp +++ b/libsolidity/analysis/OverrideChecker.cpp @@ -481,7 +481,12 @@ void OverrideChecker::checkIllegalOverrides(ContractDefinition const& _contract) for (auto const* stateVar: _contract.stateVariables()) { if (!stateVar->isPublic()) + { + if (stateVar->overrides()) + m_errorReporter.typeError(8022_error, stateVar->location(), "Override can only be used with public state variables."); + continue; + } if (contains_if(inheritedMods, MatchByName{stateVar->name()})) m_errorReporter.typeError(1456_error, stateVar->location(), "Override changes modifier to public state variable."); diff --git a/test/libsolidity/syntaxTests/inheritance/override/private_state_variable.sol b/test/libsolidity/syntaxTests/inheritance/override/private_state_variable.sol new file mode 100644 index 000000000..400da4a8e --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/override/private_state_variable.sol @@ -0,0 +1,9 @@ +contract C1 { + function f() external pure returns(int) { return 42; } +} + +contract C is C1 { + int override f; +} +// ---- +// TypeError: (96-110): Override can only be used with public state variables.