mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Improve error message for wrong struct initialization (#3359)
This commit is contained in:
parent
fdbe78a769
commit
a0771691ff
@ -9,6 +9,7 @@ Bugfixes:
|
|||||||
* Standard JSON: Populate the ``sourceLocation`` field in the error list.
|
* Standard JSON: Populate the ``sourceLocation`` field in the error list.
|
||||||
* Type Checker: Suggest the experimental ABI encoder if using ``struct``s as function parameters
|
* Type Checker: Suggest the experimental ABI encoder if using ``struct``s as function parameters
|
||||||
(instead of an internal compiler error).
|
(instead of an internal compiler error).
|
||||||
|
* Type Checker: Improve error message for wrong struct initialization.
|
||||||
|
|
||||||
### 0.4.19 (2017-11-30)
|
### 0.4.19 (2017-11-30)
|
||||||
|
|
||||||
|
@ -1551,8 +1551,12 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
|||||||
|
|
||||||
if (!functionType->takesArbitraryParameters() && parameterTypes.size() != arguments.size())
|
if (!functionType->takesArbitraryParameters() && parameterTypes.size() != arguments.size())
|
||||||
{
|
{
|
||||||
|
bool isStructConstructorCall = _functionCall.annotation().kind == FunctionCallKind::StructConstructorCall;
|
||||||
|
|
||||||
string msg =
|
string msg =
|
||||||
"Wrong argument count for function call: " +
|
"Wrong argument count for " +
|
||||||
|
string(isStructConstructorCall ? "struct constructor" : "function call") +
|
||||||
|
": " +
|
||||||
toString(arguments.size()) +
|
toString(arguments.size()) +
|
||||||
" arguments given but expected " +
|
" arguments given but expected " +
|
||||||
toString(parameterTypes.size()) +
|
toString(parameterTypes.size()) +
|
||||||
|
@ -3608,6 +3608,20 @@ BOOST_AUTO_TEST_CASE(invalid_args_creating_memory_array)
|
|||||||
CHECK_ERROR(text, TypeError, "Wrong argument count for function call: 0 arguments given but expected 1.");
|
CHECK_ERROR(text, TypeError, "Wrong argument count for function call: 0 arguments given but expected 1.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(invalid_args_creating_struct)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract C {
|
||||||
|
struct S { uint a; uint b; }
|
||||||
|
|
||||||
|
function f() public {
|
||||||
|
var s = S({a: 1});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_ERROR(text, TypeError, "Wrong argument count for struct constructor: 1 arguments given but expected 2.");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_overload_array_type)
|
BOOST_AUTO_TEST_CASE(function_overload_array_type)
|
||||||
{
|
{
|
||||||
char const* text = R"(
|
char const* text = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user