aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-03-27 22:15:34 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-03-27 22:15:34 +0800
commit621215918de0bb68c0db9369791672ec72f7bd1a (patch)
tree8d92dcfece646819325a4eda0565f838e1180cc6
parentfc0b32f68394518894314682f95a7b45fc1a6ef0 (diff)
downloaddexon-solidity-621215918de0bb68c0db9369791672ec72f7bd1a.tar.gz
dexon-solidity-621215918de0bb68c0db9369791672ec72f7bd1a.tar.zst
dexon-solidity-621215918de0bb68c0db9369791672ec72f7bd1a.zip
Abstract contract and inheritance
- Checking the linearized base contracts for abstract functions and handle their existence appropriately - If a contract is abstract it can't be created with new - An abstract contract is not compiled (no backend code is generated) - Of course tests
-rw-r--r--SolidityNameAndTypeResolution.cpp48
1 files changed, 45 insertions, 3 deletions
diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp
index 3c088358..8eb83b11 100644
--- a/SolidityNameAndTypeResolution.cpp
+++ b/SolidityNameAndTypeResolution.cpp
@@ -353,14 +353,56 @@ BOOST_AUTO_TEST_CASE(function_no_implementation)
" function functionName(bytes32 input) returns (bytes32 out);\n"
"}\n";
ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed");
- ContractDefinition* contract;
- for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
- contract = dynamic_cast<ContractDefinition*>(node.get());
+ std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->getNodes();
+ ContractDefinition* contract = dynamic_cast<ContractDefinition*>(nodes[0].get());
BOOST_CHECK(contract);
BOOST_CHECK(!contract->isFullyImplemented());
BOOST_CHECK(!contract->getDefinedFunctions()[0]->isFullyImplemented());
}
+BOOST_AUTO_TEST_CASE(abstract_contract)
+{
+ ASTPointer<SourceUnit> sourceUnit;
+ char const* text = R"(
+ contract base { function foo(); }
+ contract derived is base { function foo() {} }
+ )";
+ ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed");
+ std::vector<ASTPointer<ASTNode>> nodes = sourceUnit->getNodes();
+ ContractDefinition* base = dynamic_cast<ContractDefinition*>(nodes[0].get());
+ ContractDefinition* derived = dynamic_cast<ContractDefinition*>(nodes[1].get());
+ BOOST_CHECK(base);
+ BOOST_CHECK(!base->isFullyImplemented());
+ BOOST_CHECK(!base->getDefinedFunctions()[0]->isFullyImplemented());
+ BOOST_CHECK(derived);
+ BOOST_CHECK(derived->isFullyImplemented());
+ BOOST_CHECK(derived->getDefinedFunctions()[0]->isFullyImplemented());
+}
+
+BOOST_AUTO_TEST_CASE(create_abstract_contract)
+{
+ ASTPointer<SourceUnit> sourceUnit;
+ char const* text = R"(
+ contract base { function foo(); }
+ contract derived {
+ base b;
+ function foo() { b = new base();}
+ }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(redeclare_implemented_abstract_function_as_abstract)
+{
+ ASTPointer<SourceUnit> sourceUnit;
+ char const* text = R"(
+ contract base { function foo(); }
+ contract derived is base { function foo() {} }
+ contract wrong is derived { function foo(); }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
BOOST_AUTO_TEST_CASE(function_canonical_signature)
{
ASTPointer<SourceUnit> sourceUnit;