Check inheritance specifier arguments for interfaces.

This commit is contained in:
chriseth authored and Alex Beregszaszi committed 2017-08-22 11:39:50 +01:00
1 parent b25f0c52ac
commit 7b0046a9aa
2 files changed
+14 -5

No files matched your search

+5 -5
View File
@@ -429,12 +429,12 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
if (base->isLibrary())
m_errorReporter.typeError(_inheritance.location(), "Libraries cannot be inherited from.");
// Interface can have no constructors - no need to validate
if (base->contractKind() == ContractDefinition::ContractKind::Interface)
return;
auto const& arguments = _inheritance.arguments();
TypePointers parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
TypePointers parameterTypes;
if (base->contractKind() != ContractDefinition::ContractKind::Interface)
// Interfaces do not have constructors, so there are zero parameters.
parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
if (!arguments.empty() && parameterTypes.size() != arguments.size())
{
m_errorReporter.typeError(
@@ -6735,6 +6735,15 @@ BOOST_AUTO_TEST_CASE(accept_library_creation)
CHECK_SUCCESS(text);
}
BOOST_AUTO_TEST_CASE(reject_interface_constructors)
{
char const* text = R"(
interface I {}
contract C is I(2) {}
)";
CHECK_ERROR(text, TypeError, "Wrong argument count for constructor call: 1 arguments given but expected 0.");
}
BOOST_AUTO_TEST_SUITE_END()
}