Merge pull request #9108 from ethereum/issues-9065

Disallow override with non-public state variables
This commit is contained in:
chriseth 2020-06-03 14:22:34 +02:00 committed by GitHub
commit 0b595d28c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -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.

View File

@ -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.");

View File

@ -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.