Skip to content

Commit

Permalink
Merge pull request ethereum#3342 from ethereum/jsonio-sourcelocation
Browse files Browse the repository at this point in the history
Populate the sourceLocation field properly in standard JSON on errors
  • Loading branch information
axic authored Dec 18, 2017
2 parents 460c9f3 + add4cde commit 55752db
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Features:

Bugfixes:
* Parser: Disallow event declarations with no parameter 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
(instead of an internal compiler error).

Expand Down
4 changes: 2 additions & 2 deletions libsolidity/interface/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ Json::Value formatErrorWithException(
else
message = _message;

Json::Value sourceLocation;
if (location && location->sourceName)
{
Json::Value sourceLocation = Json::objectValue;
sourceLocation["file"] = *location->sourceName;
sourceLocation["start"] = location->start;
sourceLocation["end"] = location->end;
}

return formatError(_warning, _type, _component, message, formattedMessage, location);
return formatError(_warning, _type, _component, message, formattedMessage, sourceLocation);
}

set<string> requestedContractNames(Json::Value const& _outputSelection)
Expand Down
40 changes: 40 additions & 0 deletions test/libsolidity/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,46 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
);
}

BOOST_AUTO_TEST_CASE(compilation_error)
{
char const* input = R"(
{
"language": "Solidity",
"settings": {
"outputSelection": {
"fileA": {
"A": [
"abi"
]
}
}
},
"sources": {
"fileA": {
"content": "contract A { function }"
}
}
}
)";
Json::Value result = compile(input);
BOOST_CHECK(result.isMember("errors"));
BOOST_CHECK(result["errors"].size() >= 1);
for (auto const& error: result["errors"])
{
BOOST_REQUIRE(error.isObject());
BOOST_REQUIRE(error["message"].isString());
if (error["message"].asString().find("pre-release compiler") == string::npos)
{
BOOST_CHECK_EQUAL(
dev::jsonCompactPrint(error),
"{\"component\":\"general\",\"formattedMessage\":\"fileA:1:23: ParserError: Expected identifier, got 'RBrace'\\n"
"contract A { function }\\n ^\\n\",\"message\":\"Expected identifier, got 'RBrace'\","
"\"severity\":\"error\",\"sourceLocation\":{\"end\":22,\"file\":\"fileA\",\"start\":22},\"type\":\"ParserError\"}"
);
}
}
}

BOOST_AUTO_TEST_CASE(output_selection_explicit)
{
char const* input = R"(
Expand Down

0 comments on commit 55752db

Please sign in to comment.