Turns wrong argument count in base constructor call into en error.

This commit is contained in:
Erik Kundt 2018-07-06 22:53:55 +02:00
parent d84976dc87
commit 0b960f5a9c
3 changed files with 16 additions and 32 deletions

View File

@ -548,20 +548,7 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
if (arguments) if (arguments)
{ {
bool v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
if (parameterTypes.size() != arguments->size()) if (parameterTypes.size() != arguments->size())
{
if (arguments->size() == 0 && !v050)
m_errorReporter.warning(
_inheritance.location(),
"Wrong argument count for constructor call: " +
toString(arguments->size()) +
" arguments given but expected " +
toString(parameterTypes.size()) +
"."
);
else
{ {
m_errorReporter.typeError( m_errorReporter.typeError(
_inheritance.location(), _inheritance.location(),
@ -571,9 +558,9 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
toString(parameterTypes.size()) + toString(parameterTypes.size()) +
"." "."
); );
if (arguments->size() != 0)
return; return;
} }
}
for (size_t i = 0; i < arguments->size(); ++i) for (size_t i = 0; i < arguments->size(); ++i)
if (!type(*(*arguments)[i])->isImplicitlyConvertibleTo(*parameterTypes[i])) if (!type(*(*arguments)[i])->isImplicitlyConvertibleTo(*parameterTypes[i]))
m_errorReporter.typeError( m_errorReporter.typeError(

View File

@ -1,7 +1,13 @@
contract Base { contract Base {
constructor(uint) public {} constructor(uint) public {}
} }
contract Base2 {
constructor(uint, uint) public {}
}
contract Derived is Base(2) { } contract Derived is Base(2) { }
contract Derived2 is Base(), Derived() { } contract Derived2 is Base(), Derived() { }
contract Derived3 is Base2(2,2) { }
contract Derived4 is Base2(2), Derived() { }
// ---- // ----
// Warning: (101-107): Wrong argument count for constructor call: 0 arguments given but expected 1. // TypeError: (156-162): Wrong argument count for constructor call: 0 arguments given but expected 1.
// TypeError: (235-243): Wrong argument count for constructor call: 1 arguments given but expected 2.

View File

@ -1,9 +0,0 @@
pragma experimental "v0.5.0";
contract Base {
constructor(uint) public {}
}
contract Derived is Base(2) { }
contract Derived2 is Base(), Derived() { }
// ----
// TypeError: (132-138): Wrong argument count for constructor call: 0 arguments given but expected 1.