From 6fb537f48c7019d8450e59946237848c4e371796 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 26 Jan 2015 10:20:46 +0100 Subject: [PATCH] Reverse order of inheritance in base list. --- libsolidity/NameAndTypeResolver.cpp | 9 +++++---- test/SolidityEndToEndTest.cpp | 4 ++-- test/SolidityNameAndTypeResolution.cpp | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libsolidity/NameAndTypeResolver.cpp b/libsolidity/NameAndTypeResolver.cpp index ba5ca1345..c67cd7279 100644 --- a/libsolidity/NameAndTypeResolver.cpp +++ b/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> input(1, {&_contract}); + list> input(1, {}); for (ASTPointer const& baseSpecifier: _contract.getBaseContracts()) { ASTPointer 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 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(basesBases.begin(), basesBases.end())); } + input.back().push_front(&_contract); vector result = cThreeMerge(input); if (result.empty()) BOOST_THROW_EXCEPTION(_contract.createTypeError("Linearization of inheritance graph impossible")); diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index cf04edaad..80e9aed46 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/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; } } )"; diff --git a/test/SolidityNameAndTypeResolution.cpp b/test/SolidityNameAndTypeResolution.cpp index 6c8fd1b1c..079da0a11 100644 --- a/test/SolidityNameAndTypeResolution.cpp +++ b/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(); } } )";