From f2f0aec91c6b66a8cd5fdc2dae78debd1f4b097a Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 2 Apr 2015 15:10:35 +0200 Subject: [PATCH 1/2] Allowing abstract contracts constructor to have no args - If a constructor is part of an abstract contract we can omit its arguments - IF a contract is abstract make sure to not create and/or request Assembly code about it since it's not compiled --- SolidityNameAndTypeResolution.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index ffa78ed9e..caca8b04e 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -407,6 +407,20 @@ BOOST_AUTO_TEST_CASE(create_abstract_contract) BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); } +BOOST_AUTO_TEST_CASE(abstract_contract_constructor_args_optional) +{ + ASTPointer sourceUnit; + char const* text = R"( + contract BaseBase { function BaseBase(uint j); } + contract base is BaseBase { function foo(); } + contract derived is base { + function derived(uint i) BaseBase(i){} + function foo() {} + } + )"; + ETH_TEST_REQUIRE_NO_THROW(parseTextAndResolveNames(text), "Parsing and name resolving failed"); +} + BOOST_AUTO_TEST_CASE(redeclare_implemented_abstract_function_as_abstract) { ASTPointer sourceUnit; @@ -665,7 +679,7 @@ BOOST_AUTO_TEST_CASE(missing_base_constructor_arguments) contract A { function A(uint a) { } } contract B is A { } )"; - BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(base_constructor_arguments_override) @@ -674,7 +688,7 @@ BOOST_AUTO_TEST_CASE(base_constructor_arguments_override) contract A { function A(uint a) { } } contract B is A { } )"; - BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(implicit_derived_to_base_conversion) From a063e1c5a128cdd986c9a2f9000f4dc063f956dd Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 2 Apr 2015 16:56:12 +0200 Subject: [PATCH 2/2] Check all constructors in inheritance chain get args - Also add a missing override in a function of EnumValue --- SolidityNameAndTypeResolution.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index caca8b04e..c1a274b0c 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -421,6 +421,25 @@ BOOST_AUTO_TEST_CASE(abstract_contract_constructor_args_optional) ETH_TEST_REQUIRE_NO_THROW(parseTextAndResolveNames(text), "Parsing and name resolving failed"); } +BOOST_AUTO_TEST_CASE(abstract_contract_constructor_args_not_provided) +{ + ASTPointer sourceUnit; + char const* text = R"( + contract BaseBase { function BaseBase(uint j); } + contract base is BaseBase { function foo(); } + contract derived is base { + function derived(uint i) {} + function foo() {} + } + )"; + ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name resolving failed"); + std::vector> nodes = sourceUnit->getNodes(); + BOOST_CHECK_EQUAL(nodes.size(), 3); + ContractDefinition* derived = dynamic_cast(nodes[2].get()); + BOOST_CHECK(derived); + BOOST_CHECK(!derived->isFullyImplemented()); +} + BOOST_AUTO_TEST_CASE(redeclare_implemented_abstract_function_as_abstract) { ASTPointer sourceUnit;