Skip to content

Commit 5cf6fa8

Browse files
chrisethaxic
authored andcommitted
Provide better suggestions in error messages with respect to call and hash functions.
1 parent e299a00 commit 5cf6fa8

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

libsolidity/analysis/TypeChecker.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,23 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
17811781
for (auto const& member: membersRemovedForStructConstructor)
17821782
msg += " " + member;
17831783
}
1784+
else if (
1785+
functionType->kind() == FunctionType::Kind::BareCall ||
1786+
functionType->kind() == FunctionType::Kind::BareCallCode ||
1787+
functionType->kind() == FunctionType::Kind::BareDelegateCall
1788+
)
1789+
{
1790+
if (arguments.empty())
1791+
msg += " This function requires a single bytes argument. Use \"\" as argument to provide empty calldata.";
1792+
else
1793+
msg += " This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it.";
1794+
}
1795+
else if (
1796+
functionType->kind() == FunctionType::Kind::SHA3 ||
1797+
functionType->kind() == FunctionType::Kind::SHA256 ||
1798+
functionType->kind() == FunctionType::Kind::RIPEMD160
1799+
)
1800+
msg += " This function requires a single bytes argument. Use abi.encodePacked(...) to properly encode the values.";
17841801
m_errorReporter.typeError(_functionCall.location(), msg);
17851802
}
17861803
else if (isPositionalCall)
@@ -1817,15 +1834,28 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
18171834
}
18181835
}
18191836
else if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i]))
1820-
m_errorReporter.typeError(
1821-
arguments[i]->location(),
1837+
{
1838+
string msg =
18221839
"Invalid type for argument in function call. "
18231840
"Invalid implicit conversion from " +
18241841
type(*arguments[i])->toString() +
18251842
" to " +
18261843
parameterTypes[i]->toString() +
1827-
" requested."
1828-
);
1844+
" requested.";
1845+
if (
1846+
functionType->kind() == FunctionType::Kind::BareCall ||
1847+
functionType->kind() == FunctionType::Kind::BareCallCode ||
1848+
functionType->kind() == FunctionType::Kind::BareDelegateCall
1849+
)
1850+
msg += " This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it.";
1851+
else if (
1852+
functionType->kind() == FunctionType::Kind::SHA3 ||
1853+
functionType->kind() == FunctionType::Kind::SHA256 ||
1854+
functionType->kind() == FunctionType::Kind::RIPEMD160
1855+
)
1856+
msg += " This function requires a single bytes argument. Use abi.encodePacked(...) to properly encode the values.";
1857+
m_errorReporter.typeError(arguments[i]->location(), msg);
1858+
}
18291859
}
18301860
}
18311861
else

0 commit comments

Comments
 (0)