Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Natspec: Implement inheritance and @inheritdoc #9218

Merged
merged 1 commit into from
Jul 20, 2020
Merged

Conversation

Marenz
Copy link
Contributor

@Marenz Marenz commented Jun 17, 2020

fixes #8911

@Marenz Marenz force-pushed the issue-8911 branch 5 times, most recently from a96752e to 0039eb1 Compare June 17, 2020 12:32
Changelog.md Outdated Show resolved Hide resolved
@Marenz Marenz force-pushed the issue-8911 branch 3 times, most recently from 685f833 to 5450612 Compare June 18, 2020 10:24
@hrkrshnn
Copy link
Member

We are missing an entry in the documentation for @inheritdoc. Other than that, this looks good.

@chriseth
Copy link
Contributor

Does this both implement the explicit inheritance via @inheritdoc and the implicit inheritance or just the first?

@Marenz
Copy link
Contributor Author

Marenz commented Jun 18, 2020

@chriseth this implements both

@Marenz Marenz force-pushed the issue-8911 branch 4 times, most recently from 796e12b to e314541 Compare June 18, 2020 15:21
@hrkrshnn
Copy link
Member

There is a minor issue. According to documentation, @author is not applicable to public state variables, but applicable to functions. What should happen if a public state variable overrides a function that has an @author tag?

This could be an issue with the documentation, because when running tests, I was able to use @author on public state variables.

Copy link
Member

@christianparpart christianparpart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly constness suggestions and one boost algorithm proposal.

libsolidity/analysis/DocStringAnalyser.cpp Outdated Show resolved Hide resolved
libsolidity/analysis/DocStringAnalyser.cpp Outdated Show resolved Hide resolved
libsolidity/analysis/DocStringAnalyser.cpp Outdated Show resolved Hide resolved
libsolidity/analysis/DocStringAnalyser.cpp Outdated Show resolved Hide resolved
@Marenz Marenz force-pushed the issue-8911 branch 2 times, most recently from a955f59 to 07e4ccf Compare June 22, 2020 09:31
@Marenz
Copy link
Contributor Author

Marenz commented Jun 22, 2020

@hrkrshnn according to the code author is fine for public vars. I'll fix the docu

@Marenz
Copy link
Contributor Author

Marenz commented Jun 22, 2020

Ah well.. no.

		if (_variable.annotation().docTags.count("title") > 0 || _variable.annotation().docTags.count("author") > 0)
			m_errorReporter.warning(
				8532_error, _variable.documentation()->location(),
				"Documentation tag @title and @author is only allowed on contract definitions. "
				"It will be disallowed in 0.7.0."
			);

@@ -52,6 +52,17 @@ void copyMissingTags(StructurallyDocumentedAnnotation& _target, set<CallableDecl
_target.docTags.emplace(tag, content);
}

CallableDeclaration const* findBaseCallable(std::set<CallableDeclaration const*>& _baseFunctions, int64_t _contractId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CallableDeclaration const* findBaseCallable(std::set<CallableDeclaration const*>& _baseFunctions, int64_t _contractId)
CallableDeclaration const* findBaseCallable(set<CallableDeclaration const*> const& _baseFunctions, int64_t _contractId)

_node.documentation()->location(),
"Documentation tag @inheritdoc references contract \"" +
_annotation.inheritdocReference->name() +
"\", but the contract does not override this function."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be
"...contract does not contain a function that is overridden by this function"?

{

/**
* Parses the doc tags and does basic vadility checks.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Parses the doc tags and does basic vadility checks.
* Parses the doc tags and does basic validity checks.

5142_error,
_documentation.location(),
"Documentation tag @inheritdoc can only be given once."
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

case 1:
{
string const& name = _annotation.docTags.find("inheritdoc")->second.content;
vector<Declaration const*> results = m_resolver.nameFromCurrentScope(name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use pathFromCurrentScope to allow more complex use-cases.

@chriseth
Copy link
Contributor

chriseth commented Jul 9, 2020

Good apart from the comments!

Changelog.md Outdated
@@ -26,6 +26,7 @@ Language Features:
Compiler Features:
* NatSpec: Add fields ``kind`` and ``version`` to the JSON output.
* NatSpec: Inherit tags from unique base functions if derived function does not provide any.
* NatSpec: Implement tag ``@inheritdoc`` to copy documentation from a specific contract.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not yet fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only rebased, fixes are about to come

string const& name = _annotation.docTags.find("inheritdoc")->second.content;
vector<string> path;
boost::split(path, name, boost::is_any_of("."));
Declaration const* result = m_resolver.pathFromCurrentScope(path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a test case for that? You will need to use a multi-file test that uses import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does a resolving of a path: https:/ethereum/solidity/pull/9218/files#diff-5dcd49ff3e08e5ff224ee08fbb7ac514

It's not a contract and thus fails later but it does successfully resolve the path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please still add a multi-file test?

@Marenz Marenz force-pushed the issue-8911 branch 2 times, most recently from 6dfa28e to 636d259 Compare July 14, 2020 13:55
@@ -52,6 +52,17 @@ void copyMissingTags(StructurallyDocumentedAnnotation& _target, set<CallableDecl
_target.docTags.emplace(tag, content);
}

CallableDeclaration const* findBaseCallable(set<CallableDeclaration const*> const& _baseFunctions, int64_t _contractId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why int?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that's the type that ContractDefinition->id() returns

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Now I'm confused why id is int

}

void DocStringAnalyser::parseDocStrings(
CallableDeclaration const* DocStringAnalyser::resolveInheritDoc(
std::set<CallableDeclaration const*>& _baseFuncs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::set<CallableDeclaration const*>& _baseFuncs,
std::set<CallableDeclaration const*> const& _baseFuncs,

?

m_errorReporter.docstringParsingError(
9397_error,
_documentation.location(),
"Documentation tag @inheritdoc references unexisting contract \"" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Documentation tag @inheritdoc references unexisting contract \"" +
"Documentation tag @inheritdoc references inexistent contract \"" +

checkNatspec(sourceCode, "D", natspec, true);
}

BOOST_AUTO_TEST_CASE(dev_explicit_inherit_variable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did these tests have to be added via cpp tests? Couldn't they have been added as command line tests? (or something that is not cpp tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose anything could be a cmdline test, but this file is specifically for natspecs so it does seem to be the right place..
Whether we want/should turn the whole thing into not-cpp tests is a different question (of which I'd be in favour)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I just wondered if some similar tests had already been "converted" into cmd line tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure cmd line tests should be the favored target, maybe a more specific extension in (i)soltest would be better.

Json::Value user;
// since @notice is the only user tag if missing function should not appear
user["notice"] = Json::Value(value);
methods[it.second->externalSignature()] = user;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to these 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the code a bit, they just moved to line 74/75

);
}
break;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation looks off

"Documentation tag @" + docTag.first + " not valid for " + _nodeName + "."
);
else
if (docTag.first == "return")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (docTag.first == "return")
else if (docTag.first == "return")

if (docTag.first == "return")
{
returnTagsVisited++;
if (auto* varDecl = dynamic_cast<VariableDeclaration const*>(&_node))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (auto* varDecl = dynamic_cast<VariableDeclaration const*>(&_node))
if (auto const* varDecl = dynamic_cast<VariableDeclaration const*>(&_node))

"Documentation tag \"@" + docTag.first + "\" is only allowed once on state-variables."
);
}
else if (auto* function = dynamic_cast<FunctionDefinition const*>(&_node))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if (auto* function = dynamic_cast<FunctionDefinition const*>(&_node))
else if (auto const* function = dynamic_cast<FunctionDefinition const*>(&_node))

leonardoalt
leonardoalt previously approved these changes Jul 20, 2020
chriseth
chriseth previously approved these changes Jul 20, 2020
@chriseth chriseth merged commit e7f26c2 into develop Jul 20, 2020
@chriseth chriseth deleted the issue-8911 branch July 20, 2020 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inheritance in natspec (documentation)
6 participants