Check inheritance specifier arguments for interfaces.

This commit is contained in:
chriseth 2017-08-21 16:43:15 +02:00 committed by Alex Beregszaszi
parent b25f0c52ac
commit 7b0046a9aa
2 changed files with 14 additions and 5 deletions

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(

View File

@ -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()
}