diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index cd395c77a..c9ab551e4 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -113,9 +113,10 @@ void Parser::addStateVariableAccessor(ASTPointer const& _va vector> & _functions) { ASTNodeFactory nodeFactory(*this); + nodeFactory.setLocationEmpty(); ASTPointer emptyDoc; - ASTPointer emptyParamList; - nodeFactory.markEndPosition(); + + vector> parameters; auto expression = nodeFactory.createNode(make_shared(_varDecl->getName())); vector> block_statements = {nodeFactory.createNode(expression)}; @@ -124,9 +125,9 @@ void Parser::addStateVariableAccessor(ASTPointer const& _va true, // isPublic false, // not a Constructor emptyDoc, // no documentation - emptyParamList, // no parameters (temporary, a mapping would need parameters for example) + nodeFactory.createNode(vector>()), true, // is constant - emptyParamList, // no return parameters + nodeFactory.createNode(vector>()), nodeFactory.createNode(block_statements) ) ); diff --git a/test/SolidityParser.cpp b/test/SolidityParser.cpp index e331b9c6d..db7806f4d 100644 --- a/test/SolidityParser.cpp +++ b/test/SolidityParser.cpp @@ -66,6 +66,14 @@ ASTPointer parseTextExplainError(std::string const& _source) } } +static void checkFunctionNatspec(ASTPointer _function, + std::string const& _expectedDoc) +{ + auto doc = _function->getDocumentation(); + BOOST_CHECK_MESSAGE(doc != nullptr, "Function does not have Natspec Doc as expected"); + BOOST_CHECK_EQUAL(*doc, _expectedDoc); +} + } @@ -121,14 +129,16 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation) ASTPointer contract; ASTPointer function; char const* text = "contract test {\n" - " uint256 stateVar;\n" + " private:\n" + " uint256 stateVar;\n" + " public:\n" " /// This is a test function\n" " function functionName(hash hashin) returns (hash hashout) {}\n" "}\n"; BOOST_REQUIRE_NO_THROW(contract = parseText(text)); auto functions = contract->getDefinedFunctions(); BOOST_REQUIRE_NO_THROW(function = functions.at(0)); - BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is a test function"); + checkFunctionNatspec(function, "This is a test function"); } BOOST_AUTO_TEST_CASE(function_normal_comments) @@ -144,7 +154,7 @@ BOOST_AUTO_TEST_CASE(function_normal_comments) auto functions = contract->getDefinedFunctions(); BOOST_REQUIRE_NO_THROW(function = functions.at(0)); BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr, - "Should not have gotten a Natspect comment for this function"); + "Should not have gotten a Natspecc comment for this function"); } BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) @@ -152,7 +162,9 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) ASTPointer contract; ASTPointer function; char const* text = "contract test {\n" + " private:\n" " uint256 stateVar;\n" + " public:\n" " /// This is test function 1\n" " function functionName1(hash hashin) returns (hash hashout) {}\n" " /// This is test function 2\n" @@ -166,17 +178,17 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) auto functions = contract->getDefinedFunctions(); BOOST_REQUIRE_NO_THROW(function = functions.at(0)); - BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 1"); + checkFunctionNatspec(function, "This is test function 1"); BOOST_REQUIRE_NO_THROW(function = functions.at(1)); - BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 2"); + checkFunctionNatspec(function, "This is test function 2"); BOOST_REQUIRE_NO_THROW(function = functions.at(2)); BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr, "Should not have gotten natspec comment for functionName3()"); BOOST_REQUIRE_NO_THROW(function = functions.at(3)); - BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 4"); + checkFunctionNatspec(function, "This is test function 4"); } BOOST_AUTO_TEST_CASE(multiline_function_documentation) @@ -192,10 +204,9 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation) BOOST_REQUIRE_NO_THROW(contract = parseText(text)); auto functions = contract->getDefinedFunctions(); - BOOST_REQUIRE_NO_THROW(function = functions.at(0)); - BOOST_CHECK_EQUAL(*function->getDocumentation(), - "This is a test function\n" - " and it has 2 lines"); + BOOST_REQUIRE_NO_THROW(function = functions.at(1)); // 1 since, 0 is the index of stateVar accessor + checkFunctionNatspec(function, "This is a test function\n" + " and it has 2 lines"); } BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) @@ -211,7 +222,6 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) " mapping(address=>hash) d;\n" " string name = \"Solidity\";" " }\n" - " uint256 stateVar;\n" " /// This is a test function\n" " /// and it has 2 lines\n" " function fun(hash hashin) returns (hash hashout) {}\n" @@ -220,12 +230,11 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) auto functions = contract->getDefinedFunctions(); BOOST_REQUIRE_NO_THROW(function = functions.at(0)); - BOOST_CHECK_EQUAL(*function->getDocumentation(), "fun1 description"); + checkFunctionNatspec(function, "fun1 description"); BOOST_REQUIRE_NO_THROW(function = functions.at(1)); - BOOST_CHECK_EQUAL(*function->getDocumentation(), - "This is a test function\n" - " and it has 2 lines"); + checkFunctionNatspec(function, "This is a test function\n" + " and it has 2 lines"); } BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature)