Skip to content

Commit 9c7ceb6

Browse files
committed
fixup! Warn when layout base is near the end of storage
1 parent 36a60dd commit 9c7ceb6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

libsolidity/analysis/PostTypeContractLevelChecker.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <libsolutil/FunctionSelector.h>
3030
#include <liblangutil/ErrorReporter.h>
3131

32+
#include <range/v3/action/reverse.hpp>
33+
3234
#include <limits>
3335

3436
using namespace solidity;
@@ -148,6 +150,21 @@ void PostTypeContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinitio
148150
);
149151
}
150152

153+
namespace
154+
{
155+
156+
VariableDeclaration const* findLastStorageVariable(ContractDefinition const& _contract)
157+
{
158+
for (ContractDefinition const* baseContract: ranges::actions::reverse(_contract.annotation().linearizedBaseContracts))
159+
for (VariableDeclaration const* stateVariable: ranges::actions::reverse(baseContract->stateVariables()))
160+
if (stateVariable->referenceLocation() == VariableDeclaration::Location::Unspecified)
161+
return stateVariable;
162+
163+
return nullptr;
164+
}
165+
166+
}
167+
151168
void PostTypeContractLevelChecker::warnStorageLayoutBaseNearStorageEnd(ContractDefinition const& _contract)
152169
{
153170
// In case of most errors the warning is pointless. E.g. if we're already past storage end.
@@ -168,9 +185,11 @@ void PostTypeContractLevelChecker::warnStorageLayoutBaseNearStorageEnd(ContractD
168185
_contract.storageLayoutSpecifier()->location() :
169186
_contract.location();
170187

188+
VariableDeclaration const* lastStorageVariable = findLastStorageVariable(_contract);
189+
171190
auto errorID = 3495_error;
172191
std::string errorMsg = "This contract is very close to the end of storage. This limits its future upgradability.";
173-
if (_contract.stateVariables().size() > 0)
192+
if (lastStorageVariable)
174193
m_errorReporter.warning(
175194
errorID,
176195
location,
@@ -180,7 +199,7 @@ void PostTypeContractLevelChecker::warnStorageLayoutBaseNearStorageEnd(ContractD
180199
"There are {} storage slots between this state variable and the end of storage.",
181200
formatNumberReadable(slotsLeft)
182201
),
183-
_contract.stateVariables().back()->location()
202+
lastStorageVariable->location()
184203
)
185204
);
186205
else

0 commit comments

Comments
 (0)