Merge pull request #5957 from ethereum/function-param-fix

Ensure function parameter names always matches parameter types length
This commit is contained in:
chriseth
2019-02-11 15:45:28 +01:00
committed by GitHub
4 changed files with 71 additions and 31 deletions
+8 -15
View File
@@ -1224,10 +1224,10 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
if (!dynamic_cast<RationalNumberType const&>(*types[i]).mobileType())
m_errorReporter.fatalTypeError(components[i]->location(), "Invalid rational number.");
if (_tuple.isInlineArray())
solAssert(!!types[i], "Inline array cannot have empty components");
if (_tuple.isInlineArray())
{
solAssert(!!types[i], "Inline array cannot have empty components");
if ((i == 0 || inlineArrayType) && !types[i]->mobileType())
m_errorReporter.fatalTypeError(components[i]->location(), "Invalid mobile type.");
@@ -1677,17 +1677,10 @@ void TypeChecker::typeCheckFunctionGeneralChecks(
{
auto const& parameterNames = _functionType->parameterNames();
// Check for expected number of named arguments
if (parameterNames.size() != argumentNames.size())
{
m_errorReporter.typeError(
_functionCall.location(),
parameterNames.size() > argumentNames.size() ?
"Some argument names are missing." :
"Too many arguments."
);
return;
}
solAssert(
parameterNames.size() == argumentNames.size(),
"Unexpected parameter length mismatch!"
);
// Check for duplicate argument names
{
@@ -1971,8 +1964,8 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
_newExpression.annotation().type = make_shared<FunctionType>(
TypePointers{make_shared<IntegerType>(256)},
TypePointers{type},
strings(),
strings(),
strings(1, ""),
strings(1, ""),
FunctionType::Kind::ObjectCreation,
false,
StateMutability::Pure