29
29
#include < libsolutil/FunctionSelector.h>
30
30
#include < liblangutil/ErrorReporter.h>
31
31
32
+ #include < range/v3/action/reverse.hpp>
33
+
32
34
#include < limits>
33
35
34
36
using namespace solidity ;
@@ -148,6 +150,21 @@ void PostTypeContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinitio
148
150
);
149
151
}
150
152
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
+
151
168
void PostTypeContractLevelChecker::warnStorageLayoutBaseNearStorageEnd (ContractDefinition const & _contract)
152
169
{
153
170
// 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
168
185
_contract.storageLayoutSpecifier ()->location () :
169
186
_contract.location ();
170
187
188
+ VariableDeclaration const * lastStorageVariable = findLastStorageVariable (_contract);
189
+
171
190
auto errorID = 3495_error;
172
191
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 )
174
193
m_errorReporter.warning (
175
194
errorID,
176
195
location,
@@ -180,7 +199,7 @@ void PostTypeContractLevelChecker::warnStorageLayoutBaseNearStorageEnd(ContractD
180
199
" There are {} storage slots between this state variable and the end of storage." ,
181
200
formatNumberReadable (slotsLeft)
182
201
),
183
- _contract. stateVariables (). back () ->location ()
202
+ lastStorageVariable ->location ()
184
203
)
185
204
);
186
205
else
0 commit comments