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

Generate proper parser errors for NatSpec documentation #7835

Closed
2 of 4 tasks
erak opened this issue Nov 28, 2019 · 3 comments · Fixed by #8221
Closed
2 of 4 tasks

Generate proper parser errors for NatSpec documentation #7835

erak opened this issue Nov 28, 2019 · 3 comments · Fixed by #8221
Assignees
Milestone

Comments

@erak
Copy link
Collaborator

erak commented Nov 28, 2019

Abstract

With #7534, we introduced a (partially) breaking change: the developer documentation of a function must contain a @return tag for every named return parameter and define the parameter name as the first word after the tag. Compiling without --devdoc is still fine, but requesting it, leads to an Internal Compiler Error.

We should generate proper parser errors in the analyzation phase of a NatSpec string.

This will require some changes to the AST, since documentation needs to become an ASTNode such that it can provide source locations and, in a subsequent step, even every tag as an individual ASTNode which we can pinpoint to in case of an error.

Motivation

Consider the following contract in a file called Test.sol

pragma solidity ^0.6.0;

abstract contract C {
    /// @dev Some nice documentation
    /// @return A value
    function test() public returns (uint value);
}

Compiling it with solc Test.sol will succeed. Requesting the developer documentation using solc --devdoc will result in an Internal Compiler Error because /// @return A value does not contain the name of the return parameter as the first word after the tag.

Also, our source upgrade tool (solidity-upgrade), that is currently in development, will profit from source locations, because it would be also able to upgrade documentation then.

Specification

@Marenz
Copy link
Contributor

Marenz commented Jan 28, 2020

I see a PR from you @erak so it seems you're working on this. Assigning you

@erak
Copy link
Collaborator Author

erak commented Feb 3, 2020

I think we need to discuss the last point: "In order to report errors and their source location correctly, an additional AST node for every tag is needed."

I did some hacking on that and realized a few things that might need more work than initially thought:

  • The DocStringParser would need to create nodes, but doesn't have the full documentation string.
    Comment literals ///, /* */ etc. are filtered by the scanner before and thus the DocStringParser cannot properly compute the offset from the actual tag to the beginning of the documentation string.
  • The above would probably require proper tokenization of documentation strings in order to report the correct, "inner" source location of tags.
  • Both would need a solution which needs a good chunk of code to be rewritten (enhance scanner and parser and throw away DocStringParser)

So I would propose to post-pone the last step and at least report the location of the full documentation string in which the error occured. This will be done with: #8221.

Does anyone have further thoughts or opinions?

@chriseth
Copy link
Contributor

chriseth commented Feb 3, 2020

You are right, this sounds rather difficult with the current architecture.

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 a pull request may close this issue.

5 participants
@Marenz @elenadimitrova @chriseth @erak and others