From aa65e9423c21d65d72bc47bc4c896749b1de1ef3 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Thu, 30 Apr 2020 16:36:05 +0530 Subject: [PATCH] Uniform output in functions and constructor NatSpec --- Changelog.md | 2 +- docs/internals/layout_in_storage.rst | 4 ++-- libsolidity/interface/Natspec.cpp | 6 +++++- test/libsolidity/SolidityNatspecJSON.cpp | 18 +++++++++++------- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Changelog.md b/Changelog.md index 2eadcbe12..cc23c3a6d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,7 +11,7 @@ Compiler Features: Bugfixes: - + * NatSpec: Constructors and functions have consistent userdoc output. ### 0.6.7 (unreleased) diff --git a/docs/internals/layout_in_storage.rst b/docs/internals/layout_in_storage.rst index 0101556ef..d7aef8b25 100644 --- a/docs/internals/layout_in_storage.rst +++ b/docs/internals/layout_in_storage.rst @@ -71,7 +71,7 @@ So for the following contract snippet the position of ``data[4][9].b`` is at ``keccak256(uint256(9) . keccak256(uint256(4) . uint256(1))) + 1``:: - pragma solidity >=0.4.0 <0.7.0; + pragma solidity >=0.4.0 <0.8.0; contract C { @@ -171,7 +171,7 @@ value and reference types, types that are encoded packed, and nested types. .. code:: - pragma solidity >=0.4.0 <0.7.0; + pragma solidity >=0.4.0 <0.8.0; contract A { struct S { uint128 a; diff --git a/libsolidity/interface/Natspec.cpp b/libsolidity/interface/Natspec.cpp index b78e46081..42fcb7dee 100644 --- a/libsolidity/interface/Natspec.cpp +++ b/libsolidity/interface/Natspec.cpp @@ -42,8 +42,12 @@ Json::Value Natspec::userDocumentation(ContractDefinition const& _contractDef) { string value = extractDoc(constructorDefinition->annotation().docTags, "notice"); if (!value.empty()) + { // add the constructor, only if we have any documentation to add - methods["constructor"] = Json::Value(value); + Json::Value user; + user["notice"] = Json::Value(value); + methods["constructor"] = user; + } } string notice = extractDoc(_contractDef.annotation().docTags, "notice"); diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp index 13bd1f3b0..acb25fe29 100644 --- a/test/libsolidity/SolidityNatspecJSON.cpp +++ b/test/libsolidity/SolidityNatspecJSON.cpp @@ -849,16 +849,18 @@ BOOST_AUTO_TEST_CASE(dev_documenting_no_param_description) BOOST_AUTO_TEST_CASE(user_constructor) { - char const *sourceCode = R"( + char const* sourceCode = R"( contract test { /// @notice this is a really nice constructor constructor(uint a, uint second) public { } } )"; - char const *natspec = R"ABCDEF({ - "methods" : { - "constructor" : "this is a really nice constructor" + char const* natspec = R"ABCDEF({ + "methods": { + "constructor" : { + "notice": "this is a really nice constructor" + } } })ABCDEF"; @@ -867,7 +869,7 @@ BOOST_AUTO_TEST_CASE(user_constructor) BOOST_AUTO_TEST_CASE(user_constructor_and_function) { - char const *sourceCode = R"( + char const* sourceCode = R"( contract test { /// @notice this is a really nice constructor constructor(uint a, uint second) public { } @@ -876,12 +878,14 @@ BOOST_AUTO_TEST_CASE(user_constructor_and_function) } )"; - char const *natspec = R"ABCDEF({ + char const* natspec = R"ABCDEF({ "methods" : { "mul(uint256,uint256)" : { "notice" : "another multiplier" }, - "constructor" : "this is a really nice constructor" + "constructor" : { + "notice" : "this is a really nice constructor" + } } })ABCDEF";