From 766fa2fe85cd0c2bb8f29dc4d4deac928a86265a Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 21 Mar 2017 18:11:43 +0100 Subject: Check that contract inheriting from base with unimplemented constructor is abstract. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index c002fd3e..1388f01b 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -624,7 +624,12 @@ BOOST_AUTO_TEST_CASE(abstract_contract_constructor_args_optional) function foo() {} } )"; - ETH_TEST_REQUIRE_NO_THROW(parseAndAnalyse(text), "Parsing and name resolving failed"); + ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseAndAnalyse(text), "Parsing and name resolving failed"); + std::vector> nodes = sourceUnit->nodes(); + BOOST_CHECK_EQUAL(nodes.size(), 4); + ContractDefinition* derived = dynamic_cast(nodes[3].get()); + BOOST_REQUIRE(derived); + BOOST_CHECK(!derived->annotation().isFullyImplemented); } BOOST_AUTO_TEST_CASE(abstract_contract_constructor_args_not_provided) -- cgit v1.2.3 From 4792806b9940562184fab169923efe318e5b7793 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 21 Mar 2017 18:12:08 +0100 Subject: Fix: Contract inheriting from base with unimplemented constructor is abstract. --- libsolidity/analysis/TypeChecker.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 30e84f11..dc04404d 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -187,13 +187,20 @@ void TypeChecker::checkContractAbstractFunctions(ContractDefinition const& _cont using FunTypeAndFlag = std::pair; map> functions; + bool allBaseConstructorsImplemented = true; // Search from base to derived for (ContractDefinition const* contract: boost::adaptors::reverse(_contract.annotation().linearizedBaseContracts)) for (FunctionDefinition const* function: contract->definedFunctions()) { // Take constructors out of overload hierarchy if (function->isConstructor()) + { + if (!function->isImplemented()) + // Base contract's constructor is not fully implemented, no way to get + // out of this. + allBaseConstructorsImplemented = false; continue; + } auto& overloads = functions[function->name()]; FunctionTypePointer funType = make_shared(*function); auto it = find_if(overloads.begin(), overloads.end(), [&](FunTypeAndFlag const& _funAndFlag) @@ -211,6 +218,9 @@ void TypeChecker::checkContractAbstractFunctions(ContractDefinition const& _cont it->second = true; } + if (!allBaseConstructorsImplemented) + _contract.annotation().isFullyImplemented = false; + // Set to not fully implemented if at least one flag is false. for (auto const& it: functions) for (auto const& funAndFlag: it.second) -- cgit v1.2.3 From d8aacd5a404f7fedaec269f0d30284a8a7fc6ffc Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 21 Mar 2017 18:13:36 +0100 Subject: Changelog entry. --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 2a267fd7..5c991032 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,9 @@ Features: * Support ``interface`` contracts. +Bugfixes: + * Type system: Contract inheriting from base with unimplemented constructor should be abstract. + ### 0.4.10 (2017-03-15) Features: -- cgit v1.2.3