aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-06-08 15:48:39 +0800
committerchriseth <c@ethdev.com>2016-06-08 15:48:39 +0800
commitfd64e3b7edc0a368fce9c7c8c967a9301c214a10 (patch)
tree029b473aeafa06d1a3180f5e2a96e674c60a0929
parente97ac4fb4919b9008bd3534cd4b915b7fe70b920 (diff)
parentab7a22f4a0d95faacf453b76415eaee167aacdec (diff)
downloaddexon-solidity-fd64e3b7edc0a368fce9c7c8c967a9301c214a10.tar.gz
dexon-solidity-fd64e3b7edc0a368fce9c7c8c967a9301c214a10.tar.zst
dexon-solidity-fd64e3b7edc0a368fce9c7c8c967a9301c214a10.zip
Merge pull request #634 from chriseth/fixConstructorOverride
Fix constructor override
-rw-r--r--libsolidity/analysis/TypeChecker.cpp5
-rw-r--r--libsolidity/codegen/ContractCompiler.cpp3
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp15
3 files changed, 22 insertions, 1 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 5ae0443a..ce55de00 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -32,7 +32,7 @@ using namespace dev;
using namespace dev::solidity;
-bool TypeChecker::checkTypeRequirements(const ContractDefinition& _contract)
+bool TypeChecker::checkTypeRequirements(ContractDefinition const& _contract)
{
try
{
@@ -174,6 +174,9 @@ void TypeChecker::checkContractAbstractFunctions(ContractDefinition const& _cont
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())
+ continue;
auto& overloads = functions[function->name()];
FunctionTypePointer funType = make_shared<FunctionType>(*function);
auto it = find_if(overloads.begin(), overloads.end(), [&](FunTypeAndFlag const& _funAndFlag)
diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp
index 3623046e..bcfd33f2 100644
--- a/libsolidity/codegen/ContractCompiler.cpp
+++ b/libsolidity/codegen/ContractCompiler.cpp
@@ -776,7 +776,10 @@ void ContractCompiler::appendModifierOrFunctionCode()
{
solAssert(m_currentFunction, "");
if (m_modifierDepth >= m_currentFunction->modifiers().size())
+ {
+ solAssert(m_currentFunction->isImplemented(), "");
m_currentFunction->body().accept(*this);
+ }
else
{
ASTPointer<ModifierInvocation> const& modifierInvocation = m_currentFunction->modifiers()[m_modifierDepth];
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 3b148c9a..697b3fa9 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -544,6 +544,21 @@ BOOST_AUTO_TEST_CASE(redeclare_implemented_abstract_function_as_abstract)
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(implement_abstract_via_constructor)
+{
+ ASTPointer<SourceUnit> sourceUnit;
+ char const* text = R"(
+ contract base { function foo(); }
+ contract foo is base { function foo() {} }
+ )";
+ ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseAndAnalyse(text), "Parsing and name resolving failed");
+ std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->nodes();
+ BOOST_CHECK_EQUAL(nodes.size(), 2);
+ ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[1].get());
+ BOOST_CHECK(derived);
+ BOOST_CHECK(!derived->annotation().isFullyImplemented);
+}
+
BOOST_AUTO_TEST_CASE(function_canonical_signature)
{
ASTPointer<SourceUnit> sourceUnit;