Browse Source

Reverse order of inheritance in base list.

cl-refactor
Christian 10 years ago
parent
commit
6fb537f48c
  1. 9
      libsolidity/NameAndTypeResolver.cpp
  2. 4
      test/SolidityEndToEndTest.cpp
  3. 2
      test/SolidityNameAndTypeResolution.cpp

9
libsolidity/NameAndTypeResolver.cpp

@ -111,7 +111,7 @@ void NameAndTypeResolver::linearizeBaseContracts(ContractDefinition& _contract)
{
// order in the lists is from derived to base
// list of lists to linearize, the last element is the list of direct bases
list<list<ContractDefinition const*>> input(1, {&_contract});
list<list<ContractDefinition const*>> input(1, {});
for (ASTPointer<InheritanceSpecifier> const& baseSpecifier: _contract.getBaseContracts())
{
ASTPointer<Identifier> baseName = baseSpecifier->getName();
@ -119,14 +119,15 @@ void NameAndTypeResolver::linearizeBaseContracts(ContractDefinition& _contract)
baseName->getReferencedDeclaration());
if (!base)
BOOST_THROW_EXCEPTION(baseName->createTypeError("Contract expected."));
// "push_back" has the effect that bases mentioned earlier can overwrite members of bases
// mentioned later
input.back().push_back(base);
// "push_front" has the effect that bases mentioned later can overwrite members of bases
// mentioned earlier
input.back().push_front(base);
vector<ContractDefinition const*> const& basesBases = base->getLinearizedBaseContracts();
if (basesBases.empty())
BOOST_THROW_EXCEPTION(baseName->createTypeError("Definition of base has to precede definition of derived contract"));
input.push_front(list<ContractDefinition const*>(basesBases.begin(), basesBases.end()));
}
input.back().push_front(&_contract);
vector<ContractDefinition const*> result = cThreeMerge(input);
if (result.empty())
BOOST_THROW_EXCEPTION(_contract.createTypeError("Linearization of inheritance graph impossible"));

4
test/SolidityEndToEndTest.cpp

@ -1545,7 +1545,7 @@ BOOST_AUTO_TEST_CASE(single_copy_with_multiple_inheritance)
}
contract A is Base { function setViaA(uint i) { setData(i); } }
contract B is Base { function getViaB() returns (uint i) { return getViaBase(); } }
contract Derived is A, B, Base { }
contract Derived is Base, B, A { }
)";
compileAndRun(sourceCode, 0, "Derived");
BOOST_CHECK(callContractFunction("getViaB()") == encodeArgs(0));
@ -1642,7 +1642,7 @@ BOOST_AUTO_TEST_CASE(constructor_argument_overriding)
}
}
contract Base is BaseBase(2) { }
contract Derived is Base, BaseBase(3) {
contract Derived is BaseBase(3), Base {
function getA() returns (uint r) { return m_a; }
}
)";

2
test/SolidityNameAndTypeResolution.cpp

@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE(inheritance_diamond_basic)
contract root { function rootFunction() {} }
contract inter1 is root { function f() {} }
contract inter2 is root { function f() {} }
contract derived is inter1, inter2, root {
contract derived is root, inter2, inter1 {
function g() { f(); rootFunction(); }
}
)";

Loading…
Cancel
Save