diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-12-18 22:32:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-18 22:32:23 +0800 |
commit | 55752db9569a3d6c0253beb26465c722245a4505 (patch) | |
tree | ae39ac59506781bc8b858f16f1e2f2ff91f3992a | |
parent | 460c9f3943454ecb1679746b363ddbc5b903849b (diff) | |
parent | add4cde68cd9b5c52db8a312a34591a8bb61d8fa (diff) | |
download | dexon-solidity-55752db9569a3d6c0253beb26465c722245a4505.tar dexon-solidity-55752db9569a3d6c0253beb26465c722245a4505.tar.gz dexon-solidity-55752db9569a3d6c0253beb26465c722245a4505.tar.bz2 dexon-solidity-55752db9569a3d6c0253beb26465c722245a4505.tar.lz dexon-solidity-55752db9569a3d6c0253beb26465c722245a4505.tar.xz dexon-solidity-55752db9569a3d6c0253beb26465c722245a4505.tar.zst dexon-solidity-55752db9569a3d6c0253beb26465c722245a4505.zip |
Merge pull request #3342 from ethereum/jsonio-sourcelocation
Populate the sourceLocation field properly in standard JSON on errors
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/interface/StandardCompiler.cpp | 4 | ||||
-rw-r--r-- | test/libsolidity/StandardCompiler.cpp | 40 |
3 files changed, 43 insertions, 2 deletions
diff --git a/Changelog.md b/Changelog.md index e2325a0c..361fee9c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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). diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index ad01821e..d44254ed 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -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) diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index 091207e8..dd0478c5 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -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"( |