Skip to content

Commit 2995f04

Browse files
matheusaaguiarcameel
authored andcommitted
Improve storage layout specifier error message
1 parent d7073ba commit 2995f04

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

libsolidity/analysis/ContractLevelChecker.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <fmt/format.h>
3232

33+
#include <range/v3/algorithm/find_if.hpp>
3334
#include <range/v3/view/reverse.hpp>
3435

3536
using namespace solidity;
@@ -116,19 +117,22 @@ void ContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinition const&
116117
);
117118
}
118119

119-
for (auto const* ancestorContract: _contract.annotation().linearizedBaseContracts | ranges::views::reverse)
120+
for (auto const& baseContractSpecifier: _contract.baseContracts())
120121
{
121-
if (*ancestorContract == _contract)
122-
continue;
123-
if (ancestorContract->storageLayoutSpecifier())
122+
auto const* baseContract = dynamic_cast<ContractDefinition const*>(
123+
baseContractSpecifier->name().annotation().referencedDeclaration
124+
);
125+
126+
solAssert(baseContract);
127+
if (baseContract->storageLayoutSpecifier())
124128
m_errorReporter.typeError(
125129
8894_error,
126-
_contract.location(),
130+
baseContractSpecifier->location(),
127131
SecondarySourceLocation().append(
128-
"Storage layout was already specified here.",
129-
ancestorContract->storageLayoutSpecifier()->location()
132+
"Custom storage layout defined here:",
133+
baseContract->storageLayoutSpecifier()->location()
130134
),
131-
"Storage layout can only be specified in the most derived contract."
135+
"Cannot inherit from a contract with a custom storage layout."
132136
);
133137
}
134138
}

0 commit comments

Comments
 (0)