Disallow override with non-public state variables

This commit is contained in:
Mathias Baumann 2020-06-03 13:53:11 +02:00
parent ecc9f84f2f
commit 6f8b5fe53b
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.